Strange bug on restart application

Put your problem here if it does not fit any of the other categories.

Strange bug on restart application

Postby sufferer » Wed Feb 01, 2012 9:06 am

Hey everybody! I have very strange bug on second run application. When i run application first time- it is OK and works great.When i click "home" for "close" app. BUT if i wait some time and click on icon my application - when i see bug "Could not run application.Try again", click second time after crash starts application. This bug appear when i wait some hours. If i run second time application, for example in five minutes, then app resumes and no bug. It seems bug appear when activity was destroyed by android os.
My device - Android 2.3.3, Desire Z
Code: Select all
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blabla.unlim/com.blabla.unlim.MainScreenActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
at android.os.Handler.dispatchMessage(Handler.java:99)

some code from main activity
Code: Select all
@Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      objects = new ArrayList<ObjectData>();

      // set current type
      Settings.setAppType(this, Settings.APP_TYPE_SAFEFLEET);

      loginField = (EditText) findViewById(R.id.loginEditText);
      passField = (EditText) findViewById(R.id.passEditText);

      signInButton = (Button) findViewById(R.id.signInButton);
      signInButton.setOnClickListener(this);
   }

Can you help me,guys?
sufferer
Freshman
Freshman
 
Posts: 3
Joined: Wed Feb 01, 2012 6:40 am

Top

Re: Strange bug on restart application

Postby Phyll » Wed Feb 01, 2012 12:50 pm

Hi sufferer,

You know when you use the home key the app doesn't close. It's just put into the background. You bring it back if you press its icon again or in some other way get the OS to "start" it again. If you bring it back right away, its probably just the same as it was. After a few hours, if it has many parts, some of them might have been returned to the memory pool by the OS. You can't count on them to still be there. From the look of your error, something is no longer initialized.

What does that Settings.setAppType thing do? It doesn't seem like its all there. It doesn't seem like that should do anything. Anything good anyway.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Strange bug on restart application

Postby sufferer » Wed Feb 01, 2012 4:45 pm

Thank you for attention)
Function Settings.setAppType is static function for setting up type of application(static variable)
I know about home button and "closing" so i used a quote. I really dont understand why a cant see line with bug in my activity showed in console
sufferer
Freshman
Freshman
 
Posts: 3
Joined: Wed Feb 01, 2012 6:40 am

Re: Strange bug on restart application

Postby Phyll » Wed Feb 01, 2012 7:53 pm

Hi sufferer,

So you intended for it to be in the background and for the OS to just bring it back to the front again when you clicked its icon? Were you able to track down the line that caused the NullPointerException in your first post? I can't see enough of it, I think, to see the line number that last ran in you code. That might give you an idea what its doing. You might also put some log statements in there so you can track it and see if it does what you think it does when it ends and when it starts back up.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Strange bug on restart application

Postby BUKsAPPs » Wed Feb 01, 2012 9:05 pm

Does your static function, "Settings.setAppType()" reference an object? Is there some type of singleton type object that normally gets created before your activity, but doesn't get created when you return to it because you aren't running the APP constructor again?

More details from the LogCat should be available to give better insight.

BUKsAPPs
BUKsAPPs
Claustrum Lite - Area capture game
R:P:S Academy - play Rock/Paper/Scissors online
BUKsAPPs
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Sat Jan 16, 2010 9:01 pm
Location: USA

Re: Strange bug on restart application

Postby sufferer » Thu Feb 02, 2012 5:27 am

Great!! You are right!! But how i can restart application with my firs activity when application was destroyed? I try to use android:clearTaskOnLaunch in manifest file, but it does not work.
sufferer
Freshman
Freshman
 
Posts: 3
Joined: Wed Feb 01, 2012 6:40 am

Top

Re: Strange bug on restart application

Postby Phyll » Thu Feb 02, 2012 11:25 am

Hi sufferer,

You should put anything like that, values needed by the program, in persistent storage so that it can be restored when something like this happens. Put them in preferences or a local file. Whenever they change in the program store them. Then if they are null, restore them before you use them or just always restore them in the onResume.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests