How can I hide activity?

I have an Activity that loads a dialog into a file. And when the user clicks the "Hide" button, a notification is created and the progress dialog is hidden. And when the user clicks on the notification, the activity again shows the execution dialog in action. How to switch activity to the back task when clicking on the "Back" button?

+4
source share
2 answers

What you need to do is call finish() to remove the Activity from the stack. Then, in your notification, you call the name Activity , which is 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); 
+1
source

If you are not destroying your activity, you should set the acitvity startup mode to single_instance and use moveTaskToBack(true) to send to the background.

+6
source

Source: https://habr.com/ru/post/1435423/


All Articles