Re: [android-developers] Re: Why my service in Broadcast Receiver gone in seconds.

2016-03-25 Thread Kai Zhang
Hello,
 The broadcast receiver and service are in the same process.I guest it
is because the mobile rom is modified by the mobile manufacturer.When I
request location in the back ground.The service can not last for long.When
I change my app to another mobile the service works well.Thanks for your
reply.

Thanks,
zhangkai

2016-03-22 6:31 GMT+08:00 'Indicator Veritatis' via Android Developers <
android-developers@googlegroups.com>:

> 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  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 a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/fAdfdKyURcw/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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
> <https://groups.google.com/d/msgid/android-developers/4bcb8438-2a7f-4fc0-aea1-11637d2e22df%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CACeJ9PPH2wsmTVt_bkPM5gY83MZRu0tt-RzoCGL-pmxuPaf%3Dkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [android-developers] Re: When I get gps location in background.I got ANR

2016-03-21 Thread Kai Zhang
Hello,
Now I am clear with service.It runs in UI thread.I face a problem
that.When I start app in background I start a service in broadcast
receiver,then I start a handler thread.But the service gone for seconds,the
thread do not execute as normal.Is the service starts from broadcast
receiver not lasts long?[my code](
https://github.com/GisKook/gpstracker/tree/master/app/src/main/java/com/example/zhangkai/gpstraker
).
Thank,
zhangkai

2016-03-21 15:24 GMT+08:00 gjs :

> Hi,
>
> Yes -
>
> *Caution:* A service runs in the main thread of its hosting process—the
> service does *not* create its own thread and does *not* run in a separate
> process (unless you specify otherwise). This means that, if your service is
> going to do any CPU intensive work or blocking operations (such as MP3
> playback or networking), you should create a new thread within the service
> to do that work. By using a separate thread, you will reduce the risk of
> Application Not Responding (ANR) errors and the application's main thread
> can remain dedicated to user interaction with your activities.
> - see http://developer.android.com/guide/components/services.html
> Regards
>
>
>
> On Sunday, March 20, 2016 at 11:22:07 PM UTC+11, Kai Zhang wrote:
>>
>> Hello,
>>  I start a service from broadcast receiver.Then use thread.sleep in
>> service's onStartCommand function.Then the ANR shows.the code is here(
>> https://github.com/GisKook/testservice).So the service is in UI thread
>> too?
>> Thanks,
>> zhangkai
>>
>> 2016-03-20 16:13 GMT+08:00 gjs :
>>
>>> Hi,
>>>
>>> ANR usually means you are doing too much work on a UI thread, long
>>> running tasks should be run on other non UI threads.
>>>
>>> Regards
>>>
>>> On Saturday, March 19, 2016 at 5:43:30 PM UTC+11, Kai Zhang wrote:
>>>>
>>>> Hello,
>>>> I start a service(main service) from broadcast receiver(No 1).I know
>>>> that If I do things more than 10s android will pop a ANR window.In case of
>>>> this happen.I only request gps location for 6s.But only 6s I can not get
>>>> gps location.So I register 3 broadcast receiver.The others(broadcast
>>>> receiver No 2 and No 3) only request for gps location.The service's will
>>>> return the location value to another broadcast receiver(result collect
>>>> broadcast receiver No 4). In the No 4 receiver.If I do not do anything, The
>>>> app works correctly.But If I request for a network service It will pop ANR
>>>> sometimes.How can I debug the ANR situation?
>>>> Thanks,
>>>> zhangkai
>>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Android Developers" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/android-developers/1UT00xeVFqA/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> android-developers+unsubscr...@googlegroups.com.
>>> To post to this group, send email to android-d...@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/96fd07c6-413b-41e2-8c82-8658ad7042a5%40googlegroups.com
>>> <https://groups.google.com/d/msgid/android-developers/96fd07c6-413b-41e2-8c82-8658ad7042a5%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/1UT00xeVFqA/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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/fd0da8ab-40c5-40f7-9d54-a9ed7122721d%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/fd0da8ab-40c5-40f7-9d54-a9ed7122721d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CACeJ9PNB1MZ1Pb_-6UjQeaLUsWWgThv1rHYSjWx7wjjhFbJZNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [android-developers] Re: When I get gps location in background.I got ANR

2016-03-20 Thread Kai Zhang
https://github.com/GisKook/testservice

2016-03-20 20:17 GMT+08:00 Kai Zhang :

> Hello,
>  I start a service from broadcast receiver.Then use thread.sleep in
> service's onStartCommand function.Then the ANR shows.the code is here(
> https://github.com/GisKook/testservice).So the service is in UI thread
> too?
> Thanks,
> zhangkai
>
> 2016-03-20 16:13 GMT+08:00 gjs :
>
>> Hi,
>>
>> ANR usually means you are doing too much work on a UI thread, long
>> running tasks should be run on other non UI threads.
>>
>> Regards
>>
>> On Saturday, March 19, 2016 at 5:43:30 PM UTC+11, Kai Zhang wrote:
>>>
>>> Hello,
>>> I start a service(main service) from broadcast receiver(No 1).I know
>>> that If I do things more than 10s android will pop a ANR window.In case of
>>> this happen.I only request gps location for 6s.But only 6s I can not get
>>> gps location.So I register 3 broadcast receiver.The others(broadcast
>>> receiver No 2 and No 3) only request for gps location.The service's will
>>> return the location value to another broadcast receiver(result collect
>>> broadcast receiver No 4). In the No 4 receiver.If I do not do anything, The
>>> app works correctly.But If I request for a network service It will pop ANR
>>> sometimes.How can I debug the ANR situation?
>>> Thanks,
>>> zhangkai
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Android Developers" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/android-developers/1UT00xeVFqA/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, 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/96fd07c6-413b-41e2-8c82-8658ad7042a5%40googlegroups.com
>> <https://groups.google.com/d/msgid/android-developers/96fd07c6-413b-41e2-8c82-8658ad7042a5%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/CACeJ9PMp1dYPVEZGhyxJOgYmP-42Jb43GbeMzROYcXXL0_mBtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [android-developers] Re: When I get gps location in background.I got ANR

2016-03-20 Thread Kai Zhang
Hello,
 I start a service from broadcast receiver.Then use thread.sleep in
service's onStartCommand function.Then the ANR shows.the code is here(
https://github.com/GisKook/testservice).So the service is in UI thread too?
Thanks,
zhangkai

2016-03-20 16:13 GMT+08:00 gjs :

> Hi,
>
> ANR usually means you are doing too much work on a UI thread, long running
> tasks should be run on other non UI threads.
>
> Regards
>
> On Saturday, March 19, 2016 at 5:43:30 PM UTC+11, Kai Zhang wrote:
>>
>> Hello,
>> I start a service(main service) from broadcast receiver(No 1).I know that
>> If I do things more than 10s android will pop a ANR window.In case of this
>> happen.I only request gps location for 6s.But only 6s I can not get gps
>> location.So I register 3 broadcast receiver.The others(broadcast receiver
>> No 2 and No 3) only request for gps location.The service's will return the
>> location value to another broadcast receiver(result collect broadcast
>> receiver No 4). In the No 4 receiver.If I do not do anything, The app works
>> correctly.But If I request for a network service It will pop ANR
>> sometimes.How can I debug the ANR situation?
>> Thanks,
>> zhangkai
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/1UT00xeVFqA/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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/96fd07c6-413b-41e2-8c82-8658ad7042a5%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/96fd07c6-413b-41e2-8c82-8658ad7042a5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CACeJ9PP%3DrE6aCu%3DYB543BzZv-jfq64DbM%3DUgY84L-Oj%3DW-Y9sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] Why my service in Broadcast Receiver gone in seconds.

2016-03-19 Thread Kai Zhang
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/d7493f0e-5a8a-4e41-9e85-47d3402e2f7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] When I get gps location in background.I got ANR

2016-03-18 Thread Kai Zhang
Hello,
I start a service(main service) from broadcast receiver(No 1).I know that 
If I do things more than 10s android will pop a ANR window.In case of this 
happen.I only request gps location for 6s.But only 6s I can not get gps 
location.So I register 3 broadcast receiver.The others(broadcast receiver 
No 2 and No 3) only request for gps location.The service's will return the 
location value to another broadcast receiver(result collect broadcast 
receiver No 4). In the No 4 receiver.If I do not do anything, The app works 
correctly.But If I request for a network service It will pop ANR 
sometimes.How can I debug the ANR situation?
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/5c862fd9-39e6-48d9-aad8-59cb5f3b7d8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.