I have an app with three activities: splashscreen (default), login, main. The application starts with splash, after some seconds changes to login. If the login process is correct then we go to main.
My problem is the login activity cannot be recovered from a paused state. When I hit the Home button the onPause() is called correctly and onDestroy() is not called. Then when trying to return to the application, it starts on splash but never reaches login, it just goes back to Home. The logcat doesn’t show any error and the debugger states the application is still open (like it should). The behavior on the splash and main screens is the expected.
public class LoginActivity extends Activity {
/* UI ELEMENTS */
private OnClickListener mOnClickListener;
private EditText mPasswordField;
private EditText mUserField;
private ProgressDialog mProgressDialog;
/* LOGIC ELEMENTS */
/** handler to update interface */
private static Handler sInterfaceUpdateHandler;
public static class UpdateHandler extends Handler {
private final WeakReference<LoginActivity> mLogin;
UpdateHandler(final LoginActivity loginActivity) {
super();
mLogin = new WeakReference<LoginActivity>(loginActivity);
}
/**
* handle events from other threads in UI thread.
*
* @param message message data. Property what determines action.
*/
@Override
public void handleMessage(final Message message) {
// STUFF HERE
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.initializeInterface(); // fields filled here, listener added to buttons
}
EDIT: Activity creation in SplashScreen as per request
public class SplashScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.splashscreen);
final Thread splashThread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while (waited < 2000) {
sleep(100);
waited += 100;
}
} catch (final InterruptedException catchException) {
LoggerFactory.consoleLogger().printStackTrace(catchException);
}
SplashScreen.this.finish();
final Intent loginIntent = new Intent(SplashScreen.this, LoginActivity.class);
SplashScreen.this.startActivity(loginIntent);
}
};
splashThread.start();
}
}
Error found and fixed. The activity was marked as SingleInstance in the manifest. I changed it to SingleTop and now it works as expected.
More documentation on the cause can be found here: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode