I have Activity that download a file in progress dialog. And when user press to the button "hide" activity creates notification and hide progress dialog. And when user click to the notification, activity showing progress dialog in the activity again. How could I switch activity to the back task on pressing to the button "Back"?
How can I hide an Activity?
Asked Answered
What you need to do is to call finish()
to remove the Activity
from the stack.
Then in your notification, you set the name of the Activity
to be called when you click on it, something like this:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"A new notification", System.currentTimeMillis());
// Specify the called Activity
Intent intent = new Intent(this, YourActivityName.class);
intent.putBoolean("isDownloading", true); // check this value in Activity
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "This is the title",
"This is the text", activity);
notificationManager.notify(0, notification);
No, I don't wanna destroy the Activity beacause it contains all information about progressDialog that I will show again. Did you understand me? So sorry, my English is not good. –
Pinsky
I don't know any way to "hide" the activity unless you call "moveTaskToBack(true)" which will do what the home button does. Anyway, when you click on the notification to open the Activity onCreate() gets called, so therefore it doesn't matter if you "hide it". –
Argilliferous
In your case, I would implement a Service and bind it to this Activity, so when you click on the notification, and onCreate() is being called, check for the Intent that is being sent along with the PendingIntent, in order to get a value indicating that a download is in progress. So in your intent you can put something like: intent.putBoolean("isDownloading",true); and then you can do whatever you want depending on this boolean value. –
Argilliferous
I made it <activity android:name=".MainActivity" android:label="@string/title_activity_main" android:launchMode="singleInstance" > –
Pinsky
I mean that my activity is single instance. Thank you very much moveTaskToBack(true) - that is what I'm looked for. –
Pinsky
If you don't destroy your activity you must set acitvity launch mode to single_instance
and use moveTaskToBack(true)
to send to background.
What you need to do is to call finish()
to remove the Activity
from the stack.
Then in your notification, you set the name of the Activity
to be called when you click on it, something like this:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"A new notification", System.currentTimeMillis());
// Specify the called Activity
Intent intent = new Intent(this, YourActivityName.class);
intent.putBoolean("isDownloading", true); // check this value in Activity
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "This is the title",
"This is the text", activity);
notificationManager.notify(0, notification);
No, I don't wanna destroy the Activity beacause it contains all information about progressDialog that I will show again. Did you understand me? So sorry, my English is not good. –
Pinsky
I don't know any way to "hide" the activity unless you call "moveTaskToBack(true)" which will do what the home button does. Anyway, when you click on the notification to open the Activity onCreate() gets called, so therefore it doesn't matter if you "hide it". –
Argilliferous
In your case, I would implement a Service and bind it to this Activity, so when you click on the notification, and onCreate() is being called, check for the Intent that is being sent along with the PendingIntent, in order to get a value indicating that a download is in progress. So in your intent you can put something like: intent.putBoolean("isDownloading",true); and then you can do whatever you want depending on this boolean value. –
Argilliferous
I made it <activity android:name=".MainActivity" android:label="@string/title_activity_main" android:launchMode="singleInstance" > –
Pinsky
I mean that my activity is single instance. Thank you very much moveTaskToBack(true) - that is what I'm looked for. –
Pinsky
© 2022 - 2024 — McMap. All rights reserved.