Hi, Kai- We cannot tell from what you posted what is going on. Please take a look at how and when you create the Application, the BroadcastReceiver and the Service. Are they all in the same process? Recall that, for example, if you create the BroadcastReceiver using the <receiver> tag in the Manifest, if you specify no flags, it defaults to running in the same process as the Application (http://developer.android.com/reference/android/R.styleable.html#AndroidManifestReceiver_process).
But if, for example, the process 'hosting' the BroadcastReceiver has no other component, then when the BroadcastReceiver is done, the OS will aggressively kill the hosting process. The simplest approach is to use the same process for all three: Application, Service & BroadcastReceiver. Then the process will stick around until all three are backgrounded or killed (except under "conditions of extreme memory pressure"). See http://developer.android.com/guide/topics/processes/process-lifecycle.html for details on what is liable to be killed under what circumstances. On Saturday, March 19, 2016 at 5:53:57 AM UTC-7, Kai Zhang wrote: > > Hello all, > My app runs in background. I use alarmmanager to trig a alarm every > minutes.When my Broadcast receiver receive the alarm I start a service.But > I found that the service only last for about 4~5 seconds.I think every time > the alarmmanager trig a alarm and a new Broadcast receiver instance > created.the Broadcast receiver goes quickly.So the service gone with it?But > the android.os.Proccess.myPid() is always the same.I am confusing with it. > Thanks, > zhangkai > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/4bcb8438-2a7f-4fc0-aea1-11637d2e22df%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.