android remote process(receiver) dies quickly
i am trying to run a cpu intense task every 60 seconds. i am using AlarmManager with a PendingIntent, `
Intent intent = new Intent(MainActivity.this,AlarmReciever.class);
PendingIntent pi=PendingIntent.getBroadcast(this, 0, intent, 0);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), period, pi);
The AlarmReciever.class does some intense processing using some third-party binaries and it takes a minimum of 12 seconds to complete (when the same was tested as a single activity run). But when I run the same as a PendingIntent, I see that the remote process dies in a few seconds after starting. I get this error
03-03 03:09:45.417: INFO/ActivityManager(109): Start proc com.am:remote for broadcast com.am/.AlarmReciever: pid=7940 uid=10052 gids={1015}
03-03 03:09:55.375: WARN/ActivityManager(109): Timeout of broadcast BroadcastRecord{40a1ee80 null} - receiver=android.os.BinderProxy@4074f798, started 10003ms ago
03-03 03:09:55.375: WARN/ActivityManager(109): Receiver during timeout: ResolveInfo{40ae3380 com.am.AlarmReciever p=0 o=0 m=0x0}
03-03 03:09:56.105: ERROR/ActivityManager(109): ANR in com.am:remote
03-03 03:09:56.105: ERROR/ActivityManager(109): Reason: Broadcast of Intent { flg=0x4 cmp=com.am/.AlarmReci开发者_JAVA百科ever (has extras) }
03-03 03:09:56.105: ERROR/ActivityManager(109): Load: 1.44 / 1.42 / 1.29
in the Logcat. It says
Reason: Broadcast of Intent { flg=0x4 cmp=com.am/.AlarmReciever (has extras) }
but I am not placing any extras in the intent. But in future I would wanna place some thing.
Could some one kindly help me understand why it is closing so quickly and what can be done for the process to die only after it finishes its task.
The manifest is listed this way
<receiver android:process=":remote" android:name="AlarmReciever"></receiver>
to add on, i have tried the solution provided in this answer on SO but still no luck
Got the answer myself finally,
A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.
source: click here
精彩评论