简体   繁体   English

无论我做什么,都无法阻止我的应用程序返回到登录活动

[英]Unable to stop my application from going back to login activity no matter what i do

This is giving me a hard time, no matter what i do pressing back button return the application to login activity. 无论我按后退按钮做什么,都使我很难受,使应用程序返回登录活动。

These are the methods is I've tried so far: 这些是我到目前为止尝试过的方法:

1: I tried to set intent flags to clear top, erase history and also exclude the activity from recents. 1:我尝试设置意图标志以清除顶部,清除历史记录,并且还从最近的活动中排除活动。

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: I also tried using finish() after the startActivity() call. 2:我还尝试在startActivity()调用之后使用finish()。

Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
startActivity(intent);
finish();

Needless to say I also tried both of them at the same time too, and also tried setting the noHistory flag in manifest file just to be sure. 不用说,我也同时尝试了这两个方法,并且还尝试确保在清单文件中设置noHistory标志。 I tried overriding the back button too, yet the back button returns to the login activity. 我也尝试覆盖后退按钮,但是后退按钮返回到登录活动。

This is my manifest file: 这是我的清单文件:

<?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>

In a worst case scenario try 在最坏的情况下尝试

ActivityCompat.finishAffinity();

This will destroy the current activity without any trace, no intents can passed to other activity if this is done. 这将破坏当前活动而没有任何痕迹,如果这样做,则无法将任何意图传递给其他活动。

Happy Coding. 编码愉快。

Try This. 尝试这个。

Intent intent =new Intent(CurrentActivity.this,NextActivity.class);
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();

I am assuming your manifest should have details like his 我假设你的清单上应该有像他这样的细节

    <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" />

And MainActivity should be class Extending Activity class or AppCompatActivity 而且MainActivity应该是Extending Activity类或AppCompatActivity类
And the navigation to next screen will be 导航到下一个屏幕将是

void moveToNextScreen(){
        startActivity(new Intent(getApplicationContext(), NoticeAndStuff.class));
        this.finish();
    }

If then make sure your build files are cleaned and rebuild every time you make a code change. 如果这样的话,请确保您的构建文件在每次更改代码时都被清理并重新构建。 In Android studio it will be "Drive Path\\AppName\\app\\build" You can manually delete and try clean build again. 在Android Studio中,它将为“ Drive Path \\ AppName \\ app \\ build”。您可以手动删除并再次尝试清理构建。 Apart from these there may not be any errors. 除此之外,可能没有任何错误。

Edit: If all these are not working , then put this on your backbutton press 编辑:如果所有这些都不起作用,则将其放在您的后退按钮上

finishAffinity();

Check this for deails: API Details 检查是否失败: API详细信息

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. 通常,当可以将应用程序启动到另一个任务上时(例如从它了解的内容类型的ACTION_VIEW启动),并且用户已使用向上导航键切换到当前任务并切换到自己的任务时,通常使用此方法。 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();

I think that all thing is good, just try this which you have already done. 我认为一切都很好,只需尝试一下您已经完成的操作即可。

Intent intent = new Intent(MainActivity.this, NoticeAndStuff.class);
startActivity(intent);
finish();

but I think you need to uninstall the app from your device. 但我认为您需要从设备上卸载该应用。 Then before building and running again on the device clean and rebuild the project. 然后,在设备上再次构建并运行之前,请清理并重新构建项目。 Then Run the app and then let us know if it is the same result. 然后运行该应用程序,然后让我们知道结果是否相同。

It is little bit tricky, Try this. 这有点棘手,请尝试一下。

Using FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK will do the trick 使用FLAG_ACTIVITY_NEW_TASKFLAG_ACTIVITY_CLEAR_TASK将达到目的

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();

Happy Coding..!! 快乐编码..!

Try adding android:noHistory="true" where your login activity is declared in manifest.xml 尝试添加android:noHistory="true" ,其中在manifest.xml声明您的登录活动

If that is not working, try 如果这不起作用,请尝试

Intent i=new Intent(MainActivity.this, NoticeAndStuff.class);
i.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:从登录活动返回主活动Onbackkeypressed - Android : going back to the main activity Onbackkeypressed from login activity 在主要活动中单击“后退”按钮后,它将返回登录,如何再次停止登录 - after click back button in main activity it going to back to login ,HOW TO STOP TO GO LOGIN AGAIN 启动活动时,阻止应用程序进入前台 - Stop application from going to foreground when an activity is started 完成一项活动并返回上一个活动后,如何使用已完成活动中的变量(无 StartActivity)? - After finishing an activity and going back to a prev activity, how do I use variables from the finished activity (w/o StartActivity)? 选定的活动页面不断跳回主活动页面。 我该如何阻止这种情况发生? - Selected activity page keeps jumping back to main activity page. How do I stop this from happening? 回到活动时如何在活动上运行功能? - How do I run a function on an activity when going back to it? 如何停止按回按钮返回活动中打开的每个片段? - How to stop back press button from going back to each fragment that was opened in the activity? 关闭应用程序,而不是返回上一个活动 - Close the application instead of going back to previous activity 如何从Google+活动登录到自定义首页活动 - How do I jump from Activity my google+login to Activity my custom homepage Android:如何阻止我的编辑文本进入下一个? - Android: How do I stop my edit text from going to next one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM