单击通知时检查活动是否在屏幕上?(使用意图) [英] Check For Activity is onScreen when Notification is Clicked ?(using Intent)

查看:86
本文介绍了单击通知时检查活动是否在屏幕上?(使用意图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 android-upload-service .

我遇到的问题不是图书馆特有的.

I am facing a issue not specific to the library.

当我点击上传通知时,我想使用Intent打开一个活动.

When i am clicking on upload notification I want to open a activity using Intent.

代码:

val intent = Intent(context, EditorActivity::class.java)
            intent.putExtra("ResourceId", resourceId)//No I18N
            context.startActivity(intent)

但是

  1. 首要要求是如果活动不在屏幕上就开始活动(即应用程序可能已死,或者我可能正在进行其他活动)
  2. 第二,如果活动已经在运行,则什么也不做

我如何检查特定活动是否已死或正在运行并在屏幕上. 由于我彼此之间都具有相同的活动,因此当前代码是在当前活动的基础上开始活动.

How can i check is the specific activity is dead or running and on Screen. current code is starting the activity on top of present activity because of what i am having same activity on top of each other.

推荐答案

在清单的<activity>定义中添加launchMode="singleTop".那应该足以做您想要的.它告诉Android,如果任务中活动堆栈顶部已经存在该Activity的实例,则应该使用该Activity的现有实例,而不是创建一个新实例.

Add launchMode="singleTop" to the <activity> definition in the manifest. That should be enough to do what you want. It tells Android that it should use an existing instance of the Activity instead of creating a new one, if an instance of that Activity already exists at the top of the activity stack in the task.

请不要使用特殊的启动模式singleTasksingleInstance中的一种,因为如果您不确切地知道自己在做什么,通常会产生比解决方案更多的问题.

Please don't use one of the special launch modes singleTask or singleInstance as these usually create more problems than they solve if you do not know exactly what you are doing.

这篇关于单击通知时检查活动是否在屏幕上?(使用意图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆