0

I want to use recreate() to relaunch my activity, but I don't want it to execute the onSaveInstanceState(). So, it's really like, launching a new activity.

On this page, an answer says that:

Since API level 11 (Honeycomb), you can call the recreate() method of the activity (thanks to this answer).

The recreate() method acts just like a configuration change, so your onSaveInstanceState() and onRestoreInstanceState() methods are also called, if applicable.

Is there any other way to relaunch an activity within itself without calling onSaveInstanceState()? If you consider this bad practice, what do you think I should do?

Community
  • 1
  • 1
  • I have thought of assigning my variables their "untouched" or unmanipulated values. It's just that I was hesitant because I'd still want to see if there's a neater way to do this. –  Aug 27 '15 at 16:11

2 Answers2

0

This may not be good way, but the way I handled is reusing the intent that starts the activity. Define an intent intentOLD in the onCreate method and use intentOLD = getIntent() to retrieve the Intent that starts this activity. Then when you want to restart the activity, call finish(); startActivity(intentOLD);

Ankit Kumar
  • 3,663
  • 2
  • 26
  • 38
  • Oh, thanks. I think this will be better for going back to a certain instance. –  Aug 27 '15 at 12:40
0

have a look here.

onSavedIstanceState and onRestoreInstanceState are always called, but if you don't implement them they will recreate the app without doing anything :)

EDIT: you can add a new save to them, like an int.

when you reload but you don't wanna restore anything, you set this value for example at 1. when you reload and you want to preserve it you set it for example at 0.

than in onRestoreIstanceState you check for this value, and if it is 1 you don't call any of reload calls, if it is 0 you call them :)

Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66