在onReceive方法中的线程是否有资格在完成之前被垃圾回收?
@Override
public void onReceive(final Context context, Intent intent) {
final int alarmId = intent.getExtras().getInt(EXTRA_ALARM_ID);
Log.i(TAG, "/onReceive with an alarmVo.id of " + alarmId);
// RUN MY THREAD
new Thread(new Runnable() {
@Override
public void run() {
AlarmUtil.setNextAlarm(context, alarmId);
}
}).start();
}
根据我从这里理解:http://developer.android.com/reference/android/content/BroadcastReceiver.html ,似乎是这样,但我并不确定。
“任何需要异步操作的东西都不可用,因为您需要从函数中返回以处理异步操作,但此时BroadcastReceiver已不再运行,因此系统可以在异步操作完成之前杀死其进程。”
如果它被垃圾回收,那么如何解决这个问题?我的方法应该是什么?