Search code examples
androidandroid-intentandroid-activityandroid-pendingintentmobile-development

i am Trying more Flags to prevent the Activity to be opened more than one time at the Same time


i tried Flags like

 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_CLEAR_TASK);

i Login to my application and open the home page > when i receive a notification and preessed on it to see details at home page it opened well But the previous


Solution

  • You can achieve this with the help of launch mode

    go to manifest where your activity is declared. And add following attribute to your activity declaration.

    android:launchMode="singleTask"

    And in your activity class ovveride following method

    public void onNewIntent(Intent intent) {
       setIntent(intent);
       //do other stuff with new intent
    }
    

    I will also suggest you to read more about activity launch mode https://developer.android.com/guide/topics/manifest/activity-element.html