我有一个活动,正在执行一些下载功能。该活动将弹出一个进度对话框,在下载时禁用用户交互,并创建一个通知进度。
我希望用户能够点击通知,并返回用户的活动,有对话框显示的进度和禁用用户交互(基本上发生什么当用户去主屏幕,然后重新打开应用程序)。
我当前的尝试似乎重新启动活动,下载仍在进行,但对话框已经消失,用户交互被禁用。我该如何解决这个问题?
我的方法:
set intent action
private static void buildNotification()
{
//create intent for onClick
Intent resultIntent = new Intent(activity, activity.GetType());
resultIntent.SetAction(Intent.ActionMain);
resultIntent.AddCategory(Intent.CategoryLauncher);
PendingIntent resultPendingIntent = PendingIntent.GetActivity(activity, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
//set builder
builder.SetContentIntent(resultPendingIntent);
notificationManager = activity.GetSystemService(Context.NotificationService) as NotificationManager;
}
set intent flags
private static void buildNotification()
{
//create intent for onClick
Intent resultIntent = new Intent(activity, activity.GetType());
resultIntent.SetFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop);
PendingIntent resultPendingIntent = PendingIntent.GetActivity(activity, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
//set builder
builder.SetContentIntent(resultPendingIntent);
notificationManager = activity.GetSystemService(Context.NotificationService) as NotificationManager;
}
我最终只把SingleTop
标记在意图上。希望这对某人有所帮助:
private static void buildNotification()
{
//create intent for onClick
Intent resultIntent = new Intent(activity, activity.GetType());
resultIntent.SetFlags(ActivityFlags.SingleTop);
PendingIntent resultPendingIntent = PendingIntent.GetActivity(activity, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
//set builder
builder.SetContentIntent(resultPendingIntent);
notificationManager = activity.GetSystemService(Context.NotificationService) as NotificationManager;
}
顺便说一下,我正在使用Xamarin。Android