开发者

Android AppWidget + android:clearTaskOnLaunch="true"

开发者 https://www.devze.com 2023-02-28 09:39 出处:网络
I want my app to show a login-screen every time it is opened. With android:clearTaskOnLaunch=\"true\" everything works fine. But there is a bug which is happening only if the phone was shutdown and th

I want my app to show a login-screen every time it is opened. With android:clearTaskOnLaunch="true" everything works fine. But there is a bug which is happening only if the phone was shutdown and the app was first started with the widget.

Intent intent = new Intent(context, StartActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
[....]
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_onebyone)
views.setOnClickPendingIntent(R.id.widget, pendingInt开发者_运维问答ent);

This code should start my mainactivity. At first start is does. But ending the app with HOME and restart it with the widget causes my app to not start with my startactivity but with another activity of my app without showing the loginscreen. What can I do to fix it. I've tried

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

But it does not work. All I want is to (re)-start the StartActivity-Intent like in startActivity(..) but I found no option to give my Widget an OnClickListener which starts a "normal" Activity.

Best regards,

Till


Have you tried adding the Flag to the intent:

Intent intent = new Intent(context, StartActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
[....]
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_onebyone)
views.setOnClickPendingIntent(R.id.widget, pendingIntent);

Intent API

setFlags(int)

FLAG_ACTIVITY_CLEAR_TASK

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号