Note that there are some explanatory texts on larger screens.

plurals
  1. POonActivityResult no longer being called after onDestroy
    primarykey
    data
    text
    <p>onActivityResult is giving me major headaches. My little game has a title / menu screen. Upon clicking "new game" an Activity is launched which creates a SurfaceView for my game world. </p> <p>When playing, the player can enter buildings in the game world. Upon entering a building I launch the activity for that particular building from my SurfaveView. Here is an example:</p> <pre><code> Intent storeIntent = new Intent(mMinerClass, GeneralStore.class); storeIntent.putExtra("player", mPlayer.save()); ((Activity) mContext).startActivityForResult(storeIntent, Miner.REQUEST_STORE); </code></pre> <p>mMinerClass is defined in the game Activity onCreate:</p> <pre><code> mMap .mMinerClass = Miner.this; </code></pre> <p>mMap is the SurfaceView. I'm passing a bundle containing the state of the player. In onActivityResult I grab the bundle returned by the store activity and update the player state. </p> <pre><code> public void onActivityResult(int requestCode, int resultCode, Intent intent) { Bundle player = intent.getExtras(); mMap.mSavedPlayer = player; } </code></pre> <p>mSavedPlayer is later used to set the new player state. </p> <p><strong>All the above works generally</strong></p> <p>I can enter stores, buy stuff, leave and the player is updated correctly. </p> <p><strong>The problem</strong> manifests when I press the Home button (or someyimes back button) and onDestroy gets called. My onDestroy method does nothing besides call super.onDestroy(); </p> <p>After onDestroy() gets called onActivityResult no longer gets called. </p> <p>So:</p> <p>1) I play the game, everthing works great. </p> <p>2) I press home and ondestroy is called</p> <p>3) relaunch my game via launcher icon</p> <p>4) Resume game. I can still enter and leave stores but onActivityResult is no longer called. </p> <p>Here is some logcat output. I'm logging each time I enter a relevant method. </p> <pre><code> App start. Resuming a saved game 07-03 00:33:04.759: ERROR/Miner(4014): --&gt;onCreate 07-03 00:33:04.819: ERROR/Miner(4014): --&gt;onStart 07-03 00:33:08.329: ERROR/Miner(4014): --&gt;onResume Enter store and buy stuff 2 times. Everything working great. 07-03 00:33:30.419: ERROR/Miner(4014): --&gt;onPause 07-03 00:33:31.279: ERROR/Miner(4014): --&gt;onStop 07-03 00:33:35.069: ERROR/Miner(4014): --&gt;onActivityResult 07-03 00:33:35.069: ERROR/Miner(4014): --&gt;onRestart 07-03 00:33:35.069: ERROR/Miner(4014): --&gt;onStart 07-03 00:33:36.709: ERROR/Miner(4014): --&gt;onResume 07-03 00:33:42.129: ERROR/Miner(4014): --&gt;onPause 07-03 00:33:43.289: ERROR/Miner(4014): --&gt;onStop 07-03 00:33:55.279: ERROR/Miner(4014): --&gt;onActivityResult 07-03 00:33:55.279: ERROR/Miner(4014): --&gt;onRestart 07-03 00:33:55.279: ERROR/Miner(4014): --&gt;onStart 07-03 00:33:56.879: ERROR/Miner(4014): --&gt;onResume Back button pressed bringing me to title screen 07-03 00:35:26.283: ERROR/Miner(4014): --&gt;onPause 07-03 00:35:27.153: ERROR/Miner(4014): --&gt;onStop 07-03 00:35:27.333: ERROR/Miner(4014): --&gt;onDestroy Resume Game 07-03 00:36:12.953: ERROR/Miner(4014): --&gt;onCreate 07-03 00:36:13.003: ERROR/Miner(4014): --&gt;onStart 07-03 00:36:14.663: ERROR/Miner(4014): --&gt;onResume Enter store and buy stuff twice. No more onActivityResult 07-03 00:36:52.063: ERROR/Miner(4014): --&gt;onPause 07-03 00:36:52.863: ERROR/Miner(4014): --&gt;onStop 07-03 00:36:59.913: ERROR/Miner(4014): --&gt;onRestart 07-03 00:36:59.913: ERROR/Miner(4014): --&gt;onStart 07-03 00:37:01.593: ERROR/Miner(4014): --&gt;onResume 07-03 00:37:23.353: ERROR/Miner(4014): --&gt;onPause 07-03 00:37:24.173: ERROR/Miner(4014): --&gt;onStop 07-03 00:37:29.173: ERROR/Miner(4014): --&gt;onRestart 07-03 00:37:29.173: ERROR/Miner(4014): --&gt;onStart 07-03 00:37:30.793: ERROR/Miner(4014): --&gt;onResume </code></pre> <p>I'm posting this from my phone so excuse any dumb typos. </p> <p>I appreciate any insight y'all can provide regarding this. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload