I have published on google play my app.
Google is telling me that my app, when was being used by users, crashed 2 times.
I tested my app a lot of times, but i never get that error, and i don’t know how to simulate that error.
java.lang.RuntimeException: Unable to resume activity {com.mdp.slotmachine/com.mdp.slotmachine.CoverActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4429)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.ContextImpl.startService(ContextImpl.java:1088)
at android.content.ContextWrapper.startService(ContextWrapper.java:359)
at com.mdp.slotmachine.CoverActivity.onResume(Unknown Source)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
at android.app.Activity.performResume(Activity.java:4539)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
... 12 more
The error seems to be in CoverActivity class, inside onResume method. As you can see i don’t do anything in onResume method.
@Override
protected void onResume() {
super.onPause();
//check if i'm publishing the app on samsung store
if(MainActivity.samsung){
// here i check if my app was properly downloaded from samsung store by using Zirconia.
// BUT I NEVER GET HERE; BECAUSE THE PREVIUOS VARIABLE (MainActivity.samsung) IS ALWAYS FALSE.
if(!MainActivity.licensaSamsung){
finish();
}
}
}
As per our discussion related to your question, your approach of keeping a
final static boolean samsung;in your start Activity is fatal and wrong. This does not work on Android.Although there are reasons when you shouldn’t use static variables, I think that’s fine for such purposes as startup analysis of environment aspects.
The right way to do this on Android is to derive an Application class, perform the analysis there and store it in variables there. Typical design considerations apply, but here’s a basic scheme which may work for you.
An Instance of MyApplication is guaranteed to survive as long as you App does not get killed or is terminated. Please note that this may occur erlier or much later than you think; please try to fully understand the Application and Activity lifecycles before you try to rely on them.
With this
static singletonapproach, it’s super easy to accessApplication.isSamsung; however, you could also make it non-static and access it via the Activity’s means to find its Application context.