0

I need a method to differentiate between activity launches from the launcher or another activity's up navigation. I have a setting preference to show a tutorial the next time the app is started, but the tutorial is called when I press up on the settings activity.

I've tried the methods described here (using intent.getAction() and intent.getCategories()) Differentiating between an Activity launch from home screen or from another activity from App but they don't work when I use up navigation instead of the back button

daxter1992
  • 468
  • 3
  • 11

2 Answers2

1

Just define global static boolean and set it true eg. isLaunch=true on your main activity and apply condition to check if isLaunch = true before calling method that displays tutorial and set it to false if it is true

 public class MainActivity{

        private static boolean isLaunch = true;

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if(isLaunch){
                isLaunch = false;
                YourTutorialDisplayingMethod();
            }

       }  
    }
carefree
  • 325
  • 2
  • 3
  • 13
0

check the activity lifecycle method.OnCreate() is called only once when your activity is launched.But if you start a new activity from this activity without finishing it,then coming back from the newly opened activity using up navigation wont call the onCreate of your acticity

vs.thaakur
  • 619
  • 3
  • 13
  • 1
    It doesn't call onCreate() when I use the back button, but it does when I use the up navigation of the action bar – daxter1992 Feb 24 '15 at 04:53
  • Ok so you can use the instance state methods to set some counter and check if instance state is null then your activity is called for the first time.I guess this should work – vs.thaakur Feb 24 '15 at 05:08
  • http://stackoverflow.com/questions/9846817/when-is-the-savedinstancestate-bundle-actually-used – vs.thaakur Feb 24 '15 at 05:10
  • I don't know what's wrong but for me savedInstanceState is always null, even though onSaveInstanceState was called previously – daxter1992 Feb 24 '15 at 06:06
  • The default behaviour of UP navigation is to clear the task and restart the root activity. That's why the `Bundle` you get in `onCreate()` is null. It is starting a new instance of your `Activity`. UP navigation is a pain to get right :-( – David Wasser Feb 24 '15 at 10:43