我有一个包含三个活动的应用程序:启动画面(默认)、登录、主。应用程序以启动方式启动,几秒钟后更改为登录。如果登录过程是正确的,那么我们就去main。
我的问题是登录活动无法从暂停状态恢复。当我点击主页按钮时, onPause() 被正确调用,而 onDestroy() 没有被调用。然后,当尝试返回应用程序时,它会在启动时启动但从未到达登录,它只是回到主页。logcat 没有显示任何错误,并且调试器指出应用程序仍处于打开状态(应该如此)。初始屏幕和主屏幕上的行为是预期的。
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
}
编辑:根据请求在 SplashScreen 中创建活动
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();
}
}