0

I am having an error state in my app , so when the user doesn't have internet enabled view an xml to inform that he should connect first. The problem is that when he enables internet and tries to connect he might gets a force close. I do not know why is this but I think that if in my error state screen add code for killing the activity on exiting will help me solve this. My question is rather simple. Do I need both of them? Or only of them? Add anything else?

@Override
        protected void onStop() {
            super.onStop();
            // The activity is no longer visible (it is now "stopped")
finish();
            System.exit(0);
        }
     @Override
        protected void onDestroy() {
            super.onDestroy();
            // The activity is about to be destroyed.
finish();
            System.exit(0);

        }

The flow of my app is this: user enters the app, check if is online. If yes go to the main screen and everything goes according to the plan. If now go to the error state. So, if called, the error state will be the first activity to run (after the launching one).

EDIT: I just want to inform user that there is no connection, so please try again and because of this kill all the activities running (This is the only one actually as if it runs it will be the first). So next time he enters the app, start from the beginning not from that point that he was earlier.

qwerty_gr
  • 318
  • 3
  • 7
  • 15

3 Answers3

0

That depends. OnStop and OnDestroy have two different purposes. You should surround what ever it is that may error with a try/catch to avoid fc

@pseudo code Try: Make a connection Catch Dialog to alert that there is no connection super.finish ()

  • Can you be more specific-with an example maybe? What do you mean? I just want to inform user that there is no connection, so please try again and because of this kill all the activities running (This is the only one actually as if it runs it will be the first). So next time he enters the app, start from the beginning not from that point that he was earlier. – qwerty_gr Mar 28 '12 at 00:02
0

Never use

System.exit(0);

Let the main activity launch finished, then check connection. If there is connection, everything is fine. If not, pop up an AlertDialog which call finish() onClick.

Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56
  • why not use that? if i only leave finish() will it be a problem? – qwerty_gr Mar 29 '12 at 00:05
  • if you want to become a top notch android app developer follow the guide line of android activity life cycle. you can read here for more http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon – Win Myo Htet Mar 29 '12 at 03:29
0

Is there any problem in finishing main activity when there is no internet connection? and also when the main activity get finish , after re launching it will start from beginning.

well refer this thread :

How to close Android application?

Community
  • 1
  • 1