Android 应用程序在“退出”后重新打开

发布于 2024-11-14 23:08:25 字数 2023 浏览 2 评论 0原文

在我的应用程序上,当我退出菜单屏幕以离开应用程序时,它会重新打开并显示比主菜单更深入应用程序的视图之一。在我的调试器上,它只是简单地显示

    06-08 11:00:53.952: INFO/ActivityManager(120): Displayed activity com.app/mainmenu: 1653 ms (total 1653 ms)

//I press back to leave the app back to the main screen

    06-08 11:00:58.112: INFO/ActivityManager(120): Starting activity: Intent { cmp=com.app/gridview (has extras) }

“没有解释为什么打开该屏幕”。

我已将此方法(可能是错误的技术术语)放置在所涉及的两项活动中。

    @Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    finish();
}

关于为什么要这样做有什么想法吗?我曾考虑过插入某种“kill-app”代码,但我读到这是不明智的。

更新;感谢 inazaruk 的建议,我删除了两个屏幕上的 onBackPressed() 覆盖,它做了同样的事情。

如果我在寻找解决此问题的方法时使用了错误的术语,请有人提出建议。我确实喜欢自己解决问题。当我使用关键字(链接到本文的标签)时,我会收到很多用户留言板,而不是很多开发板。 (我有时会使用“Java”和“开发人员”这个词,但它们产生的结果与我正在寻找的结果相去甚远)

更新2:看起来我应该看看这里引用的东西 如何以编程方式关闭应用程序? 我的 gridview 可能做错了一些事情。

另一个更新:

<activity android:name=".Menu" android:label="@string/app_name" 
          android:configChanges="orientation"
          android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity android:name=".mImageGridview"
          android:configChanges="orientation"
          android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="com.hagsvision.mImageGridview" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

可能是“默认”吗?

我应该在一位女士身上尝试一下“嘿宝贝。给我看看你的清单”

解决了这个问题,在主菜单上我错误地实现了 onTouchListener。当我按下后退按钮时,它显然符合“onTouch”并且进入默认选择。我将其更改为实现 onClick 侦听器,现在它可以正常运行。

我还从清单中删除了category.DEFAULT,尽管我不认为这是问题所在。

On my application when I back out of the menu screen to leave the application it re-opens and displays one of the Views that are further into the app than the main menu. On my debugger it says simply

    06-08 11:00:53.952: INFO/ActivityManager(120): Displayed activity com.app/mainmenu: 1653 ms (total 1653 ms)

//I press back to leave the app back to the main screen

    06-08 11:00:58.112: INFO/ActivityManager(120): Starting activity: Intent { cmp=com.app/gridview (has extras) }

No explaination as to why it is opening that screen.

I have placed this Method (possibly the wrong technical term) in both of the activities that are involved.

    @Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    finish();
}

Any ideas as to why it might be doing this? I have considered inserting some sort of "kill-app" code but I have read that it's ill-advised.

update; thanks for the suggestion inazaruk, I removed the onBackPressed() override on both screens and it does the same thing.

If I am using the wrong terms when searching for a way to solve this, someone please advise. I do like solving things on my own. When I use the keywords (the tags that are linked to this article) I get alot of message boards for users and not a lot of development boards. (I throw in the word Java and developer sometimes, but they yield results far from what I am looking for)

update 2: looks like I should take a look at something referenced here
How can I programmatically close an application?
my gridview may be doing some things wrong.

Another update:

<activity android:name=".Menu" android:label="@string/app_name" 
          android:configChanges="orientation"
          android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity android:name=".mImageGridview"
          android:configChanges="orientation"
          android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="com.hagsvision.mImageGridview" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

possible that "default"?

I should try that on a lady "hey baby. Show me your manifest"

Solved it, on the main menu I was incorrectly implementing an onTouchListener. When I press the back button it apparently qualifies as an "onTouch" and it went to a default selection. I changed it to implement a onClick listener and it functions properly now.

I also removed the category.DEFAULT from the manifest though I don't think that it was the problem.

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

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

发布评论

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

评论(1

樱&纷飞 2024-11-21 23:08:25

解决了,在主菜单上我错误地实现了 onTouchListener。当我按下后退按钮时,它显然符合“onTouch”并且进入默认选择。我将其更改为实现 onClick 侦听器,现在它可以正常运行。

Solved it, on the main menu I was incorrectly implementing an onTouchListener. When I press the back button it apparently qualifies as an "onTouch" and it went to a default selection. I changed it to implement a onClick listener and it functions properly now.

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