指定为主要的新添加的活动并不总是“主要”活动。显示活动

发布于 2025-01-06 23:06:18 字数 1055 浏览 6 评论 0原文

请允许我解释一下我的困境。

我构建一个应用程序已经有一段时间了,它会立即进入我的 MainActivity.class。我在 AndroidManifest.xml 文件中声明了此 Activity,如下所示:

<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

然后我意识到我想向我的应用程序添加登录 Activity,因此需要 NewMainActivity.class。我已经能够成功地实施这个新活动。我将旧 MainActivity.class 更改为以下内容:

<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

但这就是我的问题出现的地方。

当我按登录页面上的后退键 (NewMainActivity.class) 时,它会经历 onPause()onStop() 和 <代码>onDestroy() 方法。当我再次启动应用程序时,不会显示登录页面 (NewMainActivity.class),而是显示旧的 MainActivity.class

谁能猜出我还缺少什么/做错了什么?在我看来,它现在每次都应该从登录页面开始。让我知道代码示例是否有帮助。

Allow me to explain my predicament.

I have been building an app for a while now where it would immediately enter my MainActivity.class. I had this Activity declared in the AndroidManifest.xml file as such:

<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Then I realized that I wanted to add a Login Activity to my app so a NewMainActivity.class was required. I've been able to successfully implement this new Activity. And I changed the <intent-filter> of the old MainActivity.class to the following:

<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

However this is where my problem arises.

When I press the back key on the Login Page (NewMainActivity.class) it goes through the onPause(), onStop(), and onDestroy() methods. When I start the App again the Login Page (NewMainActivity.class) is not shown, the old MainActivity.class is shown instead.

Can anyone guess what I'm still missing/doing wrong? It seems to me like it should always start on the Login Page everytime now. Let me know if a code sample would help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天气好吗我好吗 2025-01-13 23:06:18

从旧的 MainActivity.class 中删除您定义的意图过滤器:

<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

更新: 我一开始错误地理解了您的问题。我建议删除的意图过滤器除了导出您的活动之外什么也不做。这意味着任何应用程序都可以调用您的 MainActivity.class 的活动,因此,无论如何都应该将其删除。

现在介绍登录活动。据我了解,您的情况如下。当您启动应用程序时,它首先启动登录活动。然后输入您的凭据,如果登录过程成功,就会出现主要活动。

因此,堆栈中有两个活动:登录和主类。然后,当您按下主页按钮并再次运行应用程序时,它将从堆栈中的最后一个活动(即主活动)开始。

因此,问题不在于你的意图过滤器。你应该完成你的活动。在这种情况下,您将始终从登录活动开始。

Delete from your old MainActivity.class the intent-filter that you've defined:

<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Update: I've understood your question incorrectly at first. The intent-filter I've proposed to delete does nothing except exporting your activity. This means that any application can call the activity of your MainActivity.class So, in any case it should be deleted.

Now about the login activity. As I understand your scenario is the following. When you start your application it at first starts login activity. Then you enter your credentials and the main activity is appeared if the login process has been successful.

Thus, you have two activities in the stack: login and your main class. When you then push home button and run your application once again it starts from the last activity in the stack i.e. Main activity.

Thus, the problem is not in your intent-filters. You should finish your activities. In this case you'll always start from the login activity.

怀里藏娇 2025-01-13 23:06:18

如果一开始尤里的建议不起作用,并且您做了类似于我所做的事情,即在多台计算机之间复制并粘贴工作区并每次加载项目以进行 Eclipse,那么只需启动一个新项目并复制其中的实际文本即可您的所有课程都将转换为新项目中的全新课程。

If at first Yury's suggestion does not work, and you did something similar to what I did, which was copy and pasting your workspace between multiple computers and loading the project to eclipse each time, then simply start a new project and copy the actual text within all your classes to fresh new classes in the new project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文