How to check if intent/activity is already open in Android? -


so, i'm kind of noob in android searched lot , not able find solution:

in navigation drawer, each row opens new intent. how can check if intent open/active i'll use instead of creating new one?

i tried using solution:

link

but issue drawer opens same class everytime, each class has different "extras." example:

    public void itemclicked(view view, int position) {         intent intent=null;         switch (position) {             case 1:                 intent = new intent(getactivity(), displayactivity.class);                 intent.putextra("argument","section 1");                 break;             case 2:                 intent = new intent(getactivity(), displayactivity.class);                  intent.putextra("argument","section 2");                break;             case 3:                 intent = new intent(getactivity(), displayactivity.class);                 intent.putextra("argument","section 3");                 break;            }               startactivity(intent);     } 

how can check if intent class , extras open?

thanks!

you can use shared preferences or extent application class store last/current activity visible

if extend class application or targetting devices api level 14 or above can implement activitylifecyclecallbacks.

sample code

public class myapplication extends application implements activitylifecyclecallbacks {     private static boolean ismysomeactivityvisible;      @override     public void oncreate() {         super.oncreate();          // register notified of activity state changes         registeractivitylifecyclecallbacks(this);         ....     }      @override     public void onactivityresumed(activity activity) {         if (activity instanceof youractivity) {              ismysomeactivityvisible = true;         }     }      @override     public void onactivitystopped(activity activity) {         if (activity instanceof youractivity) {              ismysomeactivityvisible = false;         }     }      // other state change callback stubs     .... } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -