I wrote a game where I have activity A (main menu) and activity B (game screen).
Sometimes Android can kill my application. Then, when it's restarted, Android tries to restore activity B with default values, which are of course invalid at this time.
I know I should save and restore instance state, but there are too many variables and other things to care about, I just don't want to do it.
I am saving game progress in onStop() method, so instead I would like to simply finish activity B when system tries to restore it, and return user to the main menu from where he could load last saved game.
Long story short, I wrote this code and it works. But I'm not sure if this code is safe and will work correctly in all situations.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState!=null) {finish(); return;}
....