Reputation: 517
In my android application i start my service from background through push notification.When i receive push notification i am waking up my activity using below code:
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);
Once my activity is woke up ,i am pressing my home button.When trying to open my app by clicking Recent apps,my Incoming Activity is not shown in recent app list.This scenario happens only in redmi mi devices,the same procedure works with Motorola. How to solve this issue?
Upvotes: 5
Views: 261
Reputation: 517
The Answer for above question:
I simply use custom notification in my device systemTray while woke up incomingActivity.In onCreate() i am creating customNotification and then i clear Customnotification when the IncomingActivity goes onDestroy().
i use below code followed by method format to create 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 below code followed by method format to clear CustomNotification:
public void clearNotification()
{
if(this!=null) {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(10000);
}
}
I hope this solution is help to someone.In each android architecture has different so why i am using this format.
Thanks.
Upvotes: 2