fdmirza
fdmirza

Reputation: 311

Application respond strangely after periord of inactivity

I have an activity(say, MyActivity) that contains fragments, and i am using fragmentTransaction.replace(XX,YY) for changing fragment. After a period of inactivity when the application is resumed it behaves abnormally, and gimme the following exception (I don't know if the activity died in the meantime or what happened).

"java.lang.RuntimeException: Unable to start activity ComponentInfo{com.platinumapps.facedroid/com.platinumapps.facedroid.facedroid}: java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
    at android.app.ActivityThread.access$500(ActivityThread.java:122)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4123)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at com.platinumapps.facedroid.MyFragment.<init>(MyFragment.java:90)
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1301)
    at android.app.Fragment.instantiate(Fragment.java:560)
    at android.app.FragmentState.instantiate(Fragment.java:96)
    at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1589)
    at android.app.Activity.onCreate(Activity.java:854)
    at com.platinumapps.facedroid.facedroid.onCreate(facedroid.java:78)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
    ... 11 more
java.lang.NullPointerException
    at com.platinumapps.facedroid.MyFragment.<init>(MyFragment.java:90)
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1301)
    at android.app.Fragment.instantiate(Fragment.java:560)
    at android.app.FragmentState.instantiate(Fragment.java:96)
    at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1589)
    at android.app.Activity.onCreate(Activity.java:854)
    at com.platinumapps.facedroid.facedroid.onCreate(facedroid.java:78)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
    at android.app.ActivityThread.access$500(ActivityThread.java:122)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4123)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)

Any suggestions on it will be much appriciated. Thanks

Upvotes: 1

Views: 1606

Answers (3)

NovusMobile
NovusMobile

Reputation: 1823

you can use the :

import android.preference.PreferenceManager;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// then you use
prefs.getBoolean("keystring", true);

for more about the shared preference : just follw the question hits 150+ more in stackflow: Shared Preference

Upvotes: 0

Rotemmiz
Rotemmiz

Reputation: 7971

When stuff like this happen, it's mainly due to the fact that the whole application was closed by the system due to the need of memory, and it forced the system to call onCreate again.

Android does it's best trying to restore the previous state, and tries to open the last activity in the activity stack.

It is possible that a value being passed from another activity (by a Bundle, when using an Intent) is now null.

Try to make sure that you don't have any value that is passed from a different Activity and is not verified for it's integrity (make sure you have the condition if(value!=null) )...

EDIT

You can also override onLowMemory(), save some stuff to shared preferences, and load them when activity loads.

Upvotes: 3

OnkarDhane
OnkarDhane

Reputation: 1460

its a null pointer exception,check the values that you passing through function replace(XX,YY).put break points with debugger you will get solution defiantly. and make sure you have registered your activity in androidmanifest.xml as its sounds unable to start activity.and one important thing if your application is not responding in time for this check it Response time it will helpful for you.

Upvotes: 0

Related Questions