【发布时间】:2015-05-21 04:11:12
【问题描述】:
当用户在我的应用程序的登录屏幕上按回时应用程序崩溃。我使用下面的代码来启动我的登录活动 -
private void showLoginActivity() {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
我通过异步任务在这个屏幕上做一些后台操作。我看到 logcat 在登录活动完成并且任务仍在运行时,它在 asynctask 中显示问题。我该如何解决这个问题?
提前致谢
【问题讨论】:
-
发布您的 logcat 条目。
-
你能显示错误信息吗....logcat 信息
-
这可能是因为您从异步任务中引用了第一个活动中的对象。您可以通过在任务完成后完成 tha 活动来避免这种情况。
-
为什么你在 Activity 中使用 getApplicationContext()(finish() 调用后的假设)
标签: android android-layout android-asynctask