0

I have appwidget with listview. Some information we can see here

1) This widget don't worked on 2.x. But user on this devices see this widget at his list and can move it at screen. After he get error. Can I any way to hide this widget on 2.x? Ofcouse, I can set title for this widget as "MyWidget... (3.x-4.x). But I think this is not good.

2) Second issue. On click widget I open my application one activity (widgetAct). This is not main activity. widgetAct showed as dialog. All works, but... If I open main activity, next click HOME, not BACK. Now click on widget, opened my widgetAct, but on background I see also main activity.

3) Another case. Open widgetAct. See this activity. Click BACK. Now long press: see last started application. Click on my application (which contain widgetAct) and see this widgetAct. But want see main activity or any another activity my application, but not widgetAct.

I try different cases: add FLAG_ACTIVITY_NO_HISTORY, FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_CLEAR_TOP. But nothing help:

Intent i = new Intent(ctx, myActivityCls);      i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pi = PendingIntent.getActivity(ctx, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(viewId, pi);

I see, that my widgetAct on open have only FLAG_ACTIVITY_NEW_TASK flag.

Community
  • 1
  • 1
Yura Shinkarev
  • 5,134
  • 7
  • 34
  • 57

1 Answers1

0

I don't know why, but... I set some flags to intent and start activity on click widget. Really opened activity have only FLAG_ACTIVITY_NEW_TASK.

Solutions: 1) Move widget xml provider from xml folder to xml-v11. Now on 2.x devices this widget is hided.

2) Second case: set for widgetAct taskAffinity. But in this case at recent apps I see 2 my application instances, because used 2 stack activities. To fix it add to widgetAct:

@Override
protected void onPause() {
    super.onPause();
    finish();
}

3) On click at widget open widgetAct. I close this instance widgetAct and open another widgetAct, but add next flags: FLAG_ACTIVITY_NO_HISTORY, FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

Yura Shinkarev
  • 5,134
  • 7
  • 34
  • 57