I am trying to add upload image feature in my application, using android-upload-service.
I am facing a issue not specific to the library.
When i am clicking on upload notification I want to open a activity using Intent.
code:
val intent = Intent(context, EditorActivity::class.java)
intent.putExtra("ResourceId", resourceId)//No I18N
context.startActivity(intent)
But,
- First requirement is to start activity if it's not onScreen.(i.e application might be dead, or i might be on different activity)
- Second if the activity is already running then do nothing
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.
First, add android:launchMode="singleTask" for that activity in your AndroidManifest.xml file. This will make sure that there is only one instance of the activity at all time.
Example,
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 theActivity
instead of creating a new one, if an instance of thatActivity
already exists at the top of the activity stack in the task.Please don't use one of the special launch modes
singleTask
orsingleInstance
as these usually create more problems than they solve if you do not know exactly what you are doing.