In my code I start a new activity for street view.
Intent streetView = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(streetView);
It Launches the street view just fine. If I don't do much, I can hit the back button and my App is sitting there waiting like nothing had changed.
However, if I use street view for a bit and look around and move the view around, I see this in the logcat:
01-27 10:53:27.526: INFO/ActivityManager(1079): Low Memory: No more background processes.
01-27 10:53:27.636: DEBUG/dalvikvm(32218): GC_FOR_MALLOC freed 3054 objects / 198608 bytes in 655ms
01-27 10:53:27.831: DEBUG/dalvikvm(32164): GC_FOR_MALLOC freed 1054 objects / 51664 bytes in 342ms
01-27 10:53:27.862: INFO/dalvikvm-heap(32164): Grow heap (frag case) to 3.656MB for 87396-byte allocation
01-27 10:53:27.878: INFO/ActivityManager(1079): Process com.favorite.me (pid 32135) has died.
01-27 10:53:27.878: INFO/ActivityManager(1079): Low Memory: No more background processes.
01-27 10:53:27.482: INFO/ActivityManager(1079): Process com.myapp.app (pid 31481) has died.
01-27 10:53:27.490: INFO/WindowManager(1079): WIN DEATH: Window{44c68ba8 com.myapp.app/com.myapp.app.MyLocation paused=false}
Then when I hit the back button to return to my app, it seems like all the variable have been reset to null, like I've lost my app's state. The only way to fix it is to hit the back button again and relaunch that activity.
From what I can tell, its not calling the onpause() or the onSaveInstanceState() methods and the OS is killing off my App for memory to run streetview.
Is there something I need to do differently?
Here is my oncreate, onRestoreInstanceState and onSaveInstanceState methods:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
sLong = savedInstanceState.getDouble("sLong");
sLat = savedInstanceState.getDouble("sLat");
sMapStyle = savedInstanceState.getBoolean("sMapStyle");
sMapUpdate = savedInstanceState.getBoolean("sMapUpdate");
sMapStreet = savedInstanceState.getBoolean("sMapStreet");
sFirstTime = savedInstanceState.getBoolean("sFirstTime");
locationAvailable = savedInstanceState.getBoolean("locationAvailable");
sGPSFlag = savedInstanceState.getBoolean("sGPSFlag");
sMessage = savedInstanceState.getString("sMessage");
sMap = savedInstanceState.getString("sMap");
sGPS = savedInstanceState.getString("sGPS");
sAddressIn = savedInstanceState.getString("sAddressIn");
sGPSLat = savedInstanceState.getString("sGPSLat");
sGPSLong = savedInstanceState.getString("sGPSLong");
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putDouble("sLong",sLong);
savedInstanceState.putDouble("sLat",sLat);
savedInstanceState.putBoolean("sMapStyle",sMapStyle);
savedInstanceState.putBoolean("sMapUpdate",sMapUpdate);
savedInstanceState.putBoolean("sMapStreet",sMapStreet);
savedInstanceState.putBoolean("sFirstTime",sFirstTime);
savedInstanceState.putBoolean("locationAvailable",locationAvailable);
savedInstanceState.putBoolean("sGPSFlag",sGPSFlag);
savedInstanceState.putString("sMessage",sMessage);
savedInstanceState.putString("sMap",sMap);
savedInstanceState.putString("sGPS",sGPS);
savedInstanceState.putString("sAddressIn",sAddressIn);
savedInstanceState.putString("sGPSLat",sGPSLat);
savedInstanceState.putString("sGPSLong",sGPSLong);
}
I think I may have a lead on why this is happening. Still not sure how correct it yet.
I set some debugging messages and I am seeing the onRestoreInstanceState()
and onSaveInstanceState()
methods run.
The problem is, it is not restoring my saved instance until after my onCreate()
method finishes. But it is during the onCreate()
method that I am needing these variables which are still null at this point. How can I get my code to run after the onCreate()
but without requiring any user input? or How can I get the onRestoreInstanceState()
to run before my code?