2

I'm working on android app that lets users switch to google navigation. I've been asked to get users a solution to get back to the app without scrolling through list of open apps. I found the way to draw a button on top of everything but am struggling to get nice flow with activity life-cycle.

If user gets back to the app through manually selecting my app in list of existing apps - my app starts with onResume, However if i force my app to get back via service button it is starting with onCreate and all unsaved data i had withing my activity is getting lost.

This is the code i use to call activity back via service and button

  Intent myIntent = new Intent ( getApplicationContext(), PhoneView.class );
                    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    myIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
                    getApplicationContext().startActivity(myIntent);

I think i can putExtra bool in this call from Service and before i let user off my activity - i can save all the fields and recreate it back, but it feels like to much of extra work..

Is there a way to call my app from service and have it use existing activity, rather than to go through onCreate again assuming i know that my activity is running?

Bidhan
  • 10,607
  • 3
  • 39
  • 50
Gino
  • 317
  • 2
  • 18
  • Check out this, it might help you http://stackoverflow.com/questions/3305088/how-to-make-notification-intent-resume-rather-than-making-a-new-intent – Eric Martinez May 28 '15 at 16:24
  • 1
    Thank you Eric, i think i just fond my answer here http://stackoverflow.com/questions/12043671/notification-click-activity-already-open All you have to do is to add 1 line to activity in manifest file android:launchMode="singleTop" – Gino May 28 '15 at 16:27
  • Nice, I'll keep that in mind for my own apps. – Eric Martinez May 28 '15 at 16:28

0 Answers0