Friday, 27 April 2018

How to clear intent cache in android

How to clear intent cache in android

Android intent is a object which is used for move from one activity to another activity.

generally every one start activity like this :

Intent i=new Intent(getApplicationContext(),MainActivity.class);
startActivity(i);


Why you need to clear intent cache in android

When you move from A activity to B activity after that you move B activity to C activity when move back from C activity B activity you reach the B activity after that you move back from B activity to A activity it move on C activity because of intent cache is not clear


Example :

Intent i=new Intent(getApplicationContext(),MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

IF you want to finish current activity and move on next activity use this code : 

Intent i=new Intent(getApplicationContext(),MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();


World News Hub provide 100+ different type of newspapers and different kind of news in various languages.Click her to download




Share This

0 comments: