无论我做什么,都无法阻止我的应用程序返回登录 activity
Unable to stop my application from going back to login activity no matter what i do
这让我很难过,无论我按返回按钮 return 应用程序登录 activity。
这些是我目前尝试过的方法:
1:我尝试设置 intent 标志以清除顶部、删除历史记录并从最近的条目中排除 activity。
Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
intent.addFlags(intent.FLAG_ACTIVITY_NO_HISTORY | intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
2:我也试过在 startActivity() 调用后使用 finish()。
Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
startActivity(intent);
finish();
不用说,我也同时尝试了它们,并且还尝试在清单文件中设置 noHistory 标志以确保万无一失。我也尝试过覆盖后退按钮,但后退按钮 returns 到登录 activity。
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".app.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:noHistory="true"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".NoticeAndStuff"
android:label="@string/title_activity_notice_and_stuff"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Subscriptions"
android:label="@string/title_activity_subscriptions"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Details"
android:label="@string/title_activity_details"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Abouts"
android:label="@string/title_activity_abouts"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".FeedBack"
android:label="@string/title_activity_feed_back"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
尝试在 manifest.xml
中声明您的登录名 activity 的位置添加 android:noHistory="true"
如果这不起作用,请尝试
Intent i=new Intent(MainActivity.this, NoticeAndStuff.class);
i.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);
试试这个。
Intent intent =new Intent(CurrentActivity.this,NextActivity.class);
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
我假设你的清单应该有像他这样的细节
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NoticeAndStuff"
android:label="@string/title_activity_name"
android:theme="@style/AppTheme.NoActionBar" />
而 MainActivity 应该是 class Extending Activity class 或 AppCompatActivity
下一个屏幕的导航将是
void moveToNextScreen(){
startActivity(new Intent(getApplicationContext(), NoticeAndStuff.class));
this.finish();
}
If then 确保每次更改代码时都清理并重建构建文件。在 Android studio 中它将是 "Drive Path\AppName\app\build" 您可以手动删除并再次尝试清理构建。除了这些可能不会有任何错误。
编辑: 如果所有这些都不起作用,请将其放在后退按钮上按
finishAffinity();
查看这里了解详情:API Details
Finish this activity as well as all activities immediately below it in
the current task that have the same affinity. This is typically used
when an application can be launched on to another task (such as from
an ACTION_VIEW of a content type it understands) and the user has used
the up navigation to switch out of the current task and in to its own
task. In this case, if the user has navigated down into any other
activities of the second application, all of those should be removed
from the original task as part of the task switch.
Note that this finish does not allow you to deliver results to the
previous activity, and an exception will be thrown if you are trying
to do so.
Try this
Intent ii2 = new Intent(getApplicationContext(), FacebookSharing.class);
ii2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(ii2);
finish();
我觉得一切都很好,就试试你已经做过的吧。
Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
startActivity(intent);
finish();
但我认为您需要从您的设备上卸载该应用程序。然后在构建和 运行 之前再次在设备上清理并重建项目。然后 运行 应用程序,然后让我们知道结果是否相同。
有点棘手,试试这个。
Using FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK will do the
trick
Intent next = new Intent(CurrentActivity.this, LoginActivity.class);
// will close all the running activiities and goes to Login Activity
next.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(next);
finish();
快乐编码..!!
在最坏的情况下尝试
ActivityCompat.finishAffinity();
这将销毁当前的activity而不留下任何痕迹,如果这样做,任何意图都无法传递给其他activity。
编码愉快。
这让我很难过,无论我按返回按钮 return 应用程序登录 activity。
这些是我目前尝试过的方法:
1:我尝试设置 intent 标志以清除顶部、删除历史记录并从最近的条目中排除 activity。
Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
intent.addFlags(intent.FLAG_ACTIVITY_NO_HISTORY | intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
2:我也试过在 startActivity() 调用后使用 finish()。
Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
startActivity(intent);
finish();
不用说,我也同时尝试了它们,并且还尝试在清单文件中设置 noHistory 标志以确保万无一失。我也尝试过覆盖后退按钮,但后退按钮 returns 到登录 activity。
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".app.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:noHistory="true"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".NoticeAndStuff"
android:label="@string/title_activity_notice_and_stuff"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Subscriptions"
android:label="@string/title_activity_subscriptions"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Details"
android:label="@string/title_activity_details"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Abouts"
android:label="@string/title_activity_abouts"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".FeedBack"
android:label="@string/title_activity_feed_back"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
尝试在 manifest.xml
android:noHistory="true"
如果这不起作用,请尝试
Intent i=new Intent(MainActivity.this, NoticeAndStuff.class);
i.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);
试试这个。
Intent intent =new Intent(CurrentActivity.this,NextActivity.class);
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
我假设你的清单应该有像他这样的细节
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NoticeAndStuff"
android:label="@string/title_activity_name"
android:theme="@style/AppTheme.NoActionBar" />
而 MainActivity 应该是 class Extending Activity class 或 AppCompatActivity
下一个屏幕的导航将是
void moveToNextScreen(){
startActivity(new Intent(getApplicationContext(), NoticeAndStuff.class));
this.finish();
}
If then 确保每次更改代码时都清理并重建构建文件。在 Android studio 中它将是 "Drive Path\AppName\app\build" 您可以手动删除并再次尝试清理构建。除了这些可能不会有任何错误。
编辑: 如果所有这些都不起作用,请将其放在后退按钮上按
finishAffinity();
查看这里了解详情:API Details
Finish this activity as well as all activities immediately below it in the current task that have the same affinity. This is typically used when an application can be launched on to another task (such as from an ACTION_VIEW of a content type it understands) and the user has used the up navigation to switch out of the current task and in to its own task. In this case, if the user has navigated down into any other activities of the second application, all of those should be removed from the original task as part of the task switch.
Note that this finish does not allow you to deliver results to the previous activity, and an exception will be thrown if you are trying to do so.
Try this
Intent ii2 = new Intent(getApplicationContext(), FacebookSharing.class);
ii2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(ii2);
finish();
我觉得一切都很好,就试试你已经做过的吧。
Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
startActivity(intent);
finish();
但我认为您需要从您的设备上卸载该应用程序。然后在构建和 运行 之前再次在设备上清理并重建项目。然后 运行 应用程序,然后让我们知道结果是否相同。
有点棘手,试试这个。
Using FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK will do the trick
Intent next = new Intent(CurrentActivity.this, LoginActivity.class);
// will close all the running activiities and goes to Login Activity
next.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(next);
finish();
快乐编码..!!
在最坏的情况下尝试
ActivityCompat.finishAffinity();
这将销毁当前的activity而不留下任何痕迹,如果这样做,任何意图都无法传递给其他activity。
编码愉快。