I have a project for HoneyComb and I get an error after use recreate() method at onResum() method in my main Activity.
11-10 22:05:42.090: E/ActivityThread(1917)
You should never be calling onPause onCreate onResume
etc on your own. You shouldn't need to use recreate()
for what you want to do, put initialisation code elsewhere if it needs updating. Further, use an integer to store the state of the program instead of a string, then declare some final variables to reference e.g.
public final int RECREATE_ON = 1;
public final int RECREATE_OFF = 2;
private int recreate = RECREATE_OFF;
...
if(recreate==RECREATE_ON){
recreate();
}
Remember what recreate() is doing:
Cause this Activity to be recreated with a new instance. This results in essentially the same flow as when the Activity is created due to a configuration change -- the current instance will go through its lifecycle to onDestroy() and a new instance then created after it.
This is why you are getting the onPause
message.
To do this, use a handler:
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(msg.what==MSG_RECREATE)
recreate();
}
};
@Override
protected void onResume() {
if(condition) {
Message msg = handler.obtainMessage();
msg.what = MSG_RECREATE;
handler.sendMessage(msg);
}
}
This will not crash anymore.
I don't know if this is the cause for your problems but you don't compare Strings like this in Java;
protected void onResume() {
...
if (recreate == "S") {
recreate = "N";
recreate();
}
Use if ("S".equals(recreate))
instead.