简体   繁体   English

每次最小化应用程序时显示通知

[英]Display notification every time I minimize app

Context:语境:

My app has 5 activities:我的应用有 5 个活动:

  • SplashScreenActivity - starts service SplashScreenActivity - 启动服务
  • MainActivity - selects Activity 1,2 or 3 MainActivity - 选择 Activity 1,2 或 3
  • Activity 1活动一
  • Activity 2活动二
  • Activity 3活动 3

Currently I create notification in onCreate method of the service, which display recent activity after touching, based on目前,我在服务的onCreate方法中创建通知,该通知在触摸后显示最近的活动,基于

  1. android How to open last activity when tapping notification android 点击通知时如何打开最后一个活动
  2. Resume application and stack from notification 从通知中恢复应用程序和堆栈
  3. How to open last activity from notification status bar? 如何从通知状态栏打开上次活动?

Problem问题

setOngoing method Notification.Builder is annoying - is always here, independent if my app is in foreground or not. setOngoing方法Notification.Builder很烦人 - 总是在这里,无论我的应用程序是否在前台,都是独立的。 So I change to the setAutoCancel method, but works only for first use.所以我更改为setAutoCancel方法,但仅适用于第一次使用。 Example:例子:

I run my app - splashscreen activity (notification is shown) -> main activity -> select Activity 1 - minimize.我运行我的应用程序 - 启动屏幕活动(显示通知) -> 主要活动 -> select 活动 1 - 最小化。 Now click notification - brings Activity 1 (OK), but notification is dismissed and never shown.现在单击通知 - 带来活动 1(确定),但通知被解除且从未显示。

Question问题

How to display notification, every time I minimize app?每次最小化应用程序时如何显示通知?

Simple override onPause and put the notification logic there.简单覆盖onPause并将通知逻辑放在那里。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM