Search code examples
androidandroid-activitylaunching-application

How to check if user actually started the android app, not just returned to the activity?


How to distinguish the call of onCreate() on actual start of app or on switching activities of already started app and similar actions (like returning to the app while it is not shut down)? I've already tried to check if savedInstanceState!=null, but it only works on screen rotation, not returning to the activity from another activity of this app or another app. I also tried to get/set a special variable in onRestoreInstanceState() and onSaveInstanceState(), but it is not the solution for described cases.

How to implement this checking?


Solution

  • static boolean isFirstRun = true;
    
    public void onCreate(...) {
        if (isFirstRun) {
            // do stuff
            isFirstRun = false;
        }
    }
    

    Did you try to do something like that?