I\'m trying to implement a button that will result in my app going back to the first activity and acting as if it was (almost) restarted all over. This code
This is how I'm using IntentCompat
Intent intentToBeNewRoot = new Intent(this, MainActivity.class);
ComponentName cn = intentToBeNewRoot.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
startActivity(mainIntent);
This effectively replaces my no-longer-wanted task root with MainActivity. It works in Gingerbeard and ICS. I haven't seen the "is an undefined symbol" message.
Update
Google has removed the method IntentCompat.makeRestartActivityTask()
in current support library versions. Instead, you can just use the plain Android API:
ComponentName cn = intent.getComponent();
Intent.makeRestartActivityTask(cn);
I hope this can save someone time searching for alternatives ;)
IntentCompat is deprecated which is may be deleted, but Intent class this static method
Intent mainIntent = Intent.makeRestartActivityTask(cn);
So just use the above statement.