- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我知道,这种类型的问题有好几个,但我都试过了,还是不行。
好的,对于我的应用程序;我有一个 Activity 。在这个 Activity 中,有 4 个选项卡,第四个包含一个列表和一个记录按钮。当我推送记录时,有一个 GPS 监听器启动。获取新的 gps 值后,将其插入列表。
这到目前为止有效!
如果我单击主页按钮它仍然有效,如果我然后长按它。它在打开特定选项卡的情况下恢复该 Activity ,并且列表仍然包含列表项并且 gps 监听器仍然处于 Activity 状态。
这也很好用!
现在我想添加一个通知,它将列表的 gps 值计数显示为 .number。在每个新的 GPS 信号上,它都会用新号码更新通知图标。这没问题,但点击通知的操作完全搞砸了我的应用程序。
实际代码如下所示:
public void callNotify(String text) {
notif = new Notification();
Intent contentIntent = new Intent(this, tabactivity.class);
contentIntent.putExtra("fid", this.specialvalue);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
notif.icon = R.drawable.icon;
notif.setLatestEventInfo(this, getString(R.string.app_name), text,
PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
notif.ledARGB = Color.RED;
notif.ledOnMS = 200;
notif.ledOffMS = 200;
notif.flags = Notification.FLAG_SHOW_LIGHTS
| Notification.FLAG_ONGOING_EVENT
| Notification.FLAG_ONLY_ALERT_ONCE;
notif.number = notifyNumber;
mNotificationManager.notify(notifyNumber, notif);
}
public void updateNotify(String text) {
notifyNumber++;
notif.number = (int) (notifyNumber / 2);
Intent contentIntent = new Intent(this, tabactivity.class);
contentIntent.putExtra("fid", this.specialvalue);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
notif.setLatestEventInfo(this, getString(R.string.app_name), text,
PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT));
mNotificationManager.cancel((notifyNumber - 2));
mNotificationManager.notify(notifyNumber, notif);
}
因此,updateNotify() 在新的 gps 信号上被调用。而 callNotify() 是第一个,在它启动 gps 监听器之前。而且,是的,notifyNumber/2 是我的 Intent ,因为我会进一步处理这个数字。
如果我像这样编译它,并单击通知,它会在第一个选项卡上打开一个新的选项卡 Activity 。如果我点击回来,我会得到很多错误(数据库仍然打开,空指针和东西)。我想是因为它启动了一个新的 tabactivity 而另一个仍然打开,因为我可以看到 gps 监听器仍在工作。
所以,我想要的是,我可以执行以下操作:我打开我的应用程序,转到选项卡 Activity ,打开选项卡 4,单击记录。如果我点击返回,它应该隐藏应用程序,如果我只点击主页按钮。但是有一个通知。如果我点击那个,它应该再次显示隐藏的 Activity ,仅此而已。那么,我在那里做错了什么?我想,标志 FLAG_ACTIVITY_CLEAR_TOP 和 FLAG_ACTIVITY_SINGLE_TOP 应该可以解决问题?
最佳答案
这里发生的事情有点令人困惑,所以请耐心等待。
FLAG_ACTIVITY_SINGLE_TOP
根据文档 如果设置,如果 Activity 已经在历史堆栈的顶部运行,则不会启动。
所以如果当前 Activity 是不在历史堆栈的顶部,它将被重新启动。
FLAG_ACTIVITY_CLEAR_TOP
再次来自文档 如果设置,并且正在启动的 Activity 已经在当前任务中运行,那么不是启动该 Activity 的新实例,而是所有其他 Activity 在它之上的将被关闭,并且这个 Intent 将作为一个新的 Intent 传递给(现在在顶部的)旧 Activity。
默认情况下,TabActivity
将始终打开选项卡 0,您可以使用 setDefaultTab
通过代码更改它。 TabHost 中的每个 Tab 也是一个新的 Intent
If I compile it like this, and click on the Notification, it opens a NEW tabactivity on the first tab. If I click back then, I get alot of errors (database is still open, nullpointers and stuff).
发生这种情况我认为是因为当前的 Intent
是 tab4(实际上它是 #3, 0,1,2,3)并且您的通知正在调出tabactivity.class
。由于它不是 Activity 的或位于堆栈顶部,因此它顶部的每个 Action 都已关闭,包括 tab4。
So, what I want is, that I can do the following: I open my app, go to the tabactivity, open tab 4, click record. If I click back then, it should hide the app, also, if I just click the home button. But there is a notification. If I click on that one, it should just show the hidden acitivity again and thats it. So, what I am doing wrong there? I thought, the Flags FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP should solve the problem?
您混淆了标志的作用以及 home
和 back
键的作用。点击 home
将隐藏您的 Activity ,并且通知应该与这些标志一起正常工作(一旦您解决了我之前提到的问题)。但是,当您点击 back
时,Android 会结束当前的 Activity
并将其从堆栈中取出。由于它下面没有任何东西,因此当您按下通知时,您将被迫从头开始重新启动。
关于android - 通知恢复 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3566010/
有什么方法可以恢复删除的元素吗? 这是我删除元素的代码 myFunction() { var width = window.innerWidth; var February = doc
我有一个 TokuDB 表,由于某种原因缺少 ***_status.tokudb 文件。 我还不确定文件是否由于 TokuDB 崩溃而丢失。 问题是: 有没有办法从主要文件和关键文件(我可以从 tok
我正在 Windows 7 (x86) 上运行带有 Workbench 6.3.8 的 32 位 MySQL Server 5.7.22 本地实例(必须选择 32 位版本 - 所以,较旧的版本)。 我
1、备份 <% SQL="backup database 数据库名 to disk='"&Serve
1、ASP中怎么实现SQL数据库备份、恢复! 答:asp在线备份sql server数据库: 1、备份 <% SQL="ba
我在 R 中使用 stats::filter 函数来理解 R 中的 ARIMA 模拟(如在函数 stats::arima.sim 中)和估计。我知道 stats::filter 将线性过滤器应用于向量
我已经浏览了示例应用程序的文档和代码,并发现 files/objectbox/objectbox/data.mdb 是存储所有数据的默认文件。 假设我的理解是正确的,我有几个问题找不到文档: 我想在我
为了恢复非续订订阅类型的 InAppPurchase,我已经实现了服务器来处理此问题。 但在购买过程中,iTunes 有时不会要求用户验证他们的卡详细信息, 在这种情况下,它会在后台发送应用程序并显示
我的问题是寻找cocos2d游戏期间暂停/恢复状态(包括所有需要保存的数据信息)的设计解决方案。 包括但不限于以下情况: 1).用户选择退出,然后弹出一个对话框供用户选择“直接退出”、“暂停”; 2)
在 Mercurial 中,我有一个旧的变更集,除了对单个文件的更改外,它都很好。我将如何恢复对该单个文件的更改? 即使只是能够在上一个变更集中查看文件的状态也会很好,然后我可以剪切和粘贴。 我的 M
我的一项职能遇到了困难。我想做的是计时器在页面加载后立即启动,并且只有一个带有启动/恢复的按钮。我无法在代码中找出需要更改功能的位置。有人可以帮助我吗?谢谢! HTML: , Javascr
我正在阅读Scrap your type classes 。这为类型类提供了替代方案。然而,我被Paul Chiusano的评论所困扰。其中讨论了恢复 do 表示法 语法。 坦白说,我无法理解 ret
当 OrientDB 因某人重新启动机器而非正常关闭时,OrientDB 最终会处于数据恢复失败的状态。对于如何从这种不正常的关闭中正常恢复有什么建议吗?我们正在寻找系统在断电期间能够自行恢复的方法。
我正在构建一个 Electron 应用程序,如果发生崩溃,它必须重新加载渲染进程窗口。 目前我可以从主进程重新启动应用程序 app.relaunch(); app.quit(); 但我无法检测到窗口崩
我有 3 个 Activity ,比如说 MainActivity、 Activity 2 和 Activity 3。 在 MainActivity 中,我有一个按钮(开始/停止),当我单击此按钮时,
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 11 年前。 Improve thi
Twilio 是否支持暂停和恢复内容播放。换句话说,我有相当长的文件将播放给调用者,并且我正在尝试找到一种方法来实现暂停和恢复功能。在播放某些内容的过程中,我希望用户能够按数字暂停,然后再次按数字从音
我已经提交了 A、B、C、D 和 E。我意识到在提交 B 中发生了一些非常糟糕的事情,所以我想回到 A,这次正确地进行之前搞砸了 B 的更改,然后重新应用 C 、 D 和 E 自动。 您可能想知道为什
我的一个文件被“标记为文本”,图标也发生了变化。实际上这是一个 PHP 文件。我尝试过使用 Help -> Find Action -> Mark As 尝试将其恢复为 PHP 突出显示,但它不起作用
我有一些 SSE 程序,可以将循环中的内存归零,当指针未对齐时,它会引发 SIGSEGV进入我的处理程序。我可以在此类处理程序中获取更多信息吗例行公事,现在我不知道它是在哪里完成的,我也可以吗以某种可
我是一名优秀的程序员,十分优秀!