Why the "Activity Screen" does not show LAST applications when starting activity from a background service in a Redmi device

In my Android app, I start my service from the background through a push notification. When I receive a push notification, I wake up my activity using the code below:

Intent it = new Intent("intent.my.action"); it.setComponent(new ComponentName(context.getPackageName(),IncomingActivity.class.getName())); it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.getApplicationContext().startActivity(it); 

As soon as my activity has woken up, I press the button of my house. When I try to open my application by clicking on Recent Applications, my inbound activity does not appear in the last list of applications. This scenario only happens on redmi mi devices, the same procedure works with Motorola. How to solve this problem?

+5
source share
1 answer

The answer to the previous question:

I just use a custom notification in my systemTray system when I wake up incomingActivity.In onCreate () I create customNotification and then I clear Customnotification when IncomingActivity goes onDestroy ().

I use the code below, followed by the format of the method, to create a CustomNotification:

 public void setNoticationAfterCallAttendedView(Context view, String callerName, String status,Bitmap bitmap) { Intent notificationIntent = new Intent(view, IncomingCallActivity.class); NotificationCompat.Builder builder = new NotificationCompat.Builder(view) .setSmallIcon(R.drawable.logo,3) .setContentTitle(callerName) .setOngoing(true) .setLargeIcon(bitmap) .setContentText(status) ; PendingIntent contentIntent = PendingIntent.getActivity(view, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(10000, builder.build()); } 

i use the code below followed by the format of the method to clear CustomNotification:

 public void clearNotification() { if(this!=null) { NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.cancel(10000); } } 

I hope this solution helps someone. Each Android architecture is different, so I use this format.

Thanks.

+1
source

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


All Articles