[英]How can I launch an activity from a location on the screen, like on the home screen or in recent apps?
[英]Why “Activity Screen” doesnot shown RECENT Apps while activity launch from background service in Redmi device
在我的Android應用程序中,我通過推送通知從后台啟動我的服務。當我收到推送通知時,我正在使用以下代碼喚醒我的活動:
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);
一旦我的活動被喚醒,我按下我的主頁按鈕。當我嘗試通過單擊最近的應用程序打開我的應用程序時,我的傳入活動未顯示在最近的應用程序列表中。此方案僅在redmi mi設備中發生,相同的過程適用於摩托羅拉。 如何解決這個問題?
上述問題的答案:
我只是在我的設備systemTray中使用自定義通知,同時喚醒了incomingActivity.In onCreate()我正在創建customNotification,然后當IncomingActivity進入onDestroy()時我清除了Customnotification。
我使用下面的代碼,然后使用方法格式來創建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());
}
我使用下面的代碼,然后使用方法格式來清除CustomNotification:
public void clearNotification()
{
if(this!=null) {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(10000);
}
}
我希望這個解決方案對某人有所幫助。在每個android架構都有不同,所以為什么我使用這種格式。
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.