1

If I launch activity from service have a 5 seconds delay to start. Delay is not black or write screen. Simply not start.

Intent i = new Intent(ServiceClass.getServiceContext(), KioskActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ServiceClass.getServiceContext().startActivity(i);

If I launch same activity from other activity, delay is 0,5 - 1 seconds. In this case I launch activity wich no Flag, from service I use FLAG_ACTIVITY_NEW_TASK.

The process in OnCreate (computational cost) of launched activity is the same if is launched from service or from other activity.

Why it takes much longer launch from the service?

Extra info:

If I launch activity from service when any other activity of app is opened activity open above in 0.5 seconds delay, if I launch activity from service when is NOT other activity opened delay is 5 seconds.

Jimmy Kane
  • 16,223
  • 11
  • 86
  • 117
user3782779
  • 1,669
  • 3
  • 22
  • 36
  • just wandering. what happens if you launch it from another activity with the same flags? – Ahmed Hegazy Apr 05 '16 at 16:19
  • If I launch from another activity with the same flag delay is 0.5 seconds, so, this is not the problem. – user3782779 Apr 05 '16 at 16:22
  • @user3782779 try detaching it from the debug cable and run again – Rod_Algonquin Apr 05 '16 at 16:27
  • Can you post the whole Service class? I just can't see the problem in those 3 lines! – Ahmed Hegazy Apr 05 '16 at 16:28
  • @Rod_Algonquin I Try and this is not the problem – user3782779 Apr 05 '16 at 16:30
  • @Ahmed Hegazy My service class is very big and have a lot of computational cost. Is procesing video camera frames, Could that be the problem? Then I create one service only to launch activities? – user3782779 Apr 05 '16 at 16:31
  • may be, but you can't know for sure until tracing the whole service and know what's the problem exactly and why it takes so long. You can use the TraceView, find further instructions here http://developer.android.com/tools/debugging/debugging-tracing.html – Ahmed Hegazy Apr 05 '16 at 16:38
  • just call `startActivity`, no reason of calling `getServiceContext` whatever it is – pskink Apr 05 '16 at 16:49
  • @pskink startActivity must be called from context, if you don´t have activity context, you need service context. – user3782779 Apr 05 '16 at 16:51
  • your code is `Service`'s code, isnt it? a `Service` extends `android.content.ContextWrapper` – pskink Apr 05 '16 at 16:52
  • No, Is from Timer code. – user3782779 Apr 05 '16 at 17:07
  • `Why it takes much longer launch from the service?` so is it Service or Timer? start it from your Service and see the results – pskink Apr 05 '16 at 17:35
  • @pskink I start from Timer but wich service context because Timer don´t have context. Must start from Timer. – user3782779 Apr 05 '16 at 19:52
  • just start it from your service and see if anything changes in timings – pskink Apr 05 '16 at 19:55
  • refer this , http://stackoverflow.com/questions/25927102/delay-while-launching-activity-from-service and https://code.google.com/p/android/issues/detail?id=4536 – siddharthsn Nov 22 '16 at 22:37
  • 1
    Does this answer your question? [Starting an activity from a service after HOME button pressed without the 5 seconds delay](https://stackoverflow.com/questions/5600084/starting-an-activity-from-a-service-after-home-button-pressed-without-the-5-seco) – Sam Feb 14 '20 at 19:36

0 Answers0