Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - detecting application launch from home or history

What is the best way to detect when an Android "Application" has been launched from the Home screen/History screen?

Basically, what I'm trying to achieve is force the user to login to certain screens each time they come back to the app (i.e. they have full access to all activities once logged in, but essentially I want them to re-authenticate when they come back to the app via launching on the home screen).

I know similar questions have been asked before (i.e. how to log launches of an app) - but none that I have seen has yet been able to solve my problem. All ideas welcome...

like image 365
Codz Avatar asked Mar 27 '11 07:03

Codz


People also ask

How does Android know which activity to run first?

Activities will very often need to support the CATEGORY_DEFAULT so that they can be found by Context. startActivity(). So, CATEGORY_DEFAULT can appear number of times. Android does not grab whichever one appears first in the manifest but it starts with activity having CATEGORY_LAUNCHER.

How do I find out when an app was installed for the first time?

Navigate to APPS and select the app u want by long press. And then hit the Info button on top right corner. Thats it , it will show u the modified or installed time.

How do I find my first app launch Android?

There's no reliable way to detect first run, as the shared preferences way is not always safe, the user can delete the shared preferences data from the settings! a better way is to use the answers here Is there a unique Android device ID? to get the device's unique ID and store it somewhere in your server, so whenever ...


1 Answers

What about

    if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY )!=0) {
        Log.d(TAG, "Called from history");
    }

? This uses a simple Intent flag.

like image 128
bk138 Avatar answered Oct 07 '22 18:10

bk138