1

I am developing a simple app, but I got an error and I'm not quite sure why this error occurred.

I was playing a game and then exited the game. My app must be in the backstack because it gave me an error as soon as the game finished.

I took an event log right after the error occurred on my phone. It's as follows (com.myapp is my app) :

game finishes :

06-16 00:32:41.291 I/am_finish_activity(  630): [0,813606986,4357,com.kabam.marvelbattle/com.explodingbarrel.Activity,app-request]
06-16 00:32:41.297 I/am_home_stack_moved(  630): [0,0,1,1,finishActivity adjustTopFocus setFocusedActivity]

My app gains focus :

06-16 00:32:41.303 I/am_focused_activity(  630): [0,com.myapp/.MainActivity]
06-16 00:32:41.327 I/am_pause_activity(  630): [0,813606986,com.kabam.marvelbattle/com.explodingbarrel.Activity]
06-16 00:32:41.891 I/am_proc_start(  630): [0,9039,10178,com.myapp,activity,com.myapp/.MainActivity]
06-16 00:32:41.949 I/am_proc_bound(  630): [0,9039,com.myapp]
06-16 00:32:42.002 I/configuration_changed(  630): 1152

My app activity restart :

06-16 00:32:42.068 I/am_restart_activity(  630): [0,871748964,4355,com.myapp/.MainActivity]
06-16 00:32:42.088 I/dvm_lock_sample(  630): [system_server,1,ActivityManager,87,ActivityManagerService.java,1782,-,6242,17]
06-16 00:32:42.118 I/force_gc(  630): Binder
06-16 00:32:42.680 I/am_proc_start(  630): [0,9073,10053,com.svox.pico,service,com.svox.pico/.PicoService]
06-16 00:32:42.755 I/am_proc_bound(  630): [0,9073,com.svox.pico]

NullPointer Exception :

06-16 00:32:42.917 I/am_crash(  630): [9039,0,com.myapp,8961606,java.lang.NullPointerException,Attempt to invoke virtual method 'void com.myapp.beans.FieldHolder.setTitle(java.lang.String)' on a null object reference,ThirdFragment.java,26]

To clarify the NullPointerException :

I have one activity (MainActivity) with a

public void replaceFragment(...) {
    // ...
    fragmentTransaction.replace(..)
    // ...
}

method.

This method is called in MainActivity.onCreate().

Whenever the user navigates in the app this method is called which replaces the fragment currently shown. While doing so it injects a "FieldHolder" class instance into the fragment.

After exiting the game, Android clearly tried to restart my application with ThirdFragment as the currently shown fragment.

But in the error above, ThirdFragment never got the FieldHolder class instance, in other words Android system didn't call replaceFragment(..) method of MainActivity on am_restart_activity.

How can I prevent this error ?

Note : I'm guessing I have to override onResume method in MainActivity and call replaceFragment(..) in it but how can I know which Fragment is to be shown ? (In this case ThirdActivity ?)

comrade
  • 4,590
  • 5
  • 33
  • 48
Wolf359
  • 2,620
  • 4
  • 42
  • 62
  • 1
    The FragmentManager.findFragmentById method should be able to tell you which Fragment is loaded in it. However, a [mcve] of your issue would be nice, as well as the full logcat error – OneCricketeer Jun 17 '16 at 13:04
  • Not an answer though but a pointer -- Check the process ID of your app and match it with the current process id. If it matches all is well if it does not, you have to handle and write some code. – Skynet Jun 17 '16 at 13:09

0 Answers0