androidandroid-activitylaunchmode

Android singleTop Activity issue


I declared my activity as singleTop in the manifest file. I am passing some value with intent when I launching this activity.

Intent i= new Intent(A.this,MysingleTopActivity.class);
i.putExtra("isActive",true);
startActivity(i);

same steps I am doing for restart activity from class B.

Intent i= new Intent(B.this,MysingleTopActivity.class);
i.putExtra("isActive",false);
startActivity(i);

so for this I am getting call in onNewIntent() method of MysingleTopActivity. with isActive =false.

but if I rotate the screen then onCreate() will call and in that "isActive=true".

how can I retrieve current instance value of that activity?

Thanks


Solution

  • For achieving this result need to add

    setIntent(newintent); 
    

    in onNewIntent(Intent newintent) {} methold so on rotation of screen newintent will delivered on onCreate();

    sample code:

        @Override
        protected void onNewIntent(Intent intent) {
            super.onNewIntent(intent);
            setIntent(intent);
    //add your code
    }