ListView in the widget stop working after 60sec

0

I have a problem with my application widget. The widget contains a listView and update button. The ListView can be also updated automatically, which works fine, but the problem is, that in every 60second from the widget update (no matter if automatic or manual) I cannot click on my items on the list. I can scroll but I cannot click. After a manual or automatic updates, click on the item start again working, but only for 60sec. When I cannot click, in the logCat is popping up this: ActivityManager: Background start not allowed: service intent { flg =0x10000000....... Here is my code: public class WidgetService extends RemoteViewsService

@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
    int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    return new WidgetMailsAdapter(widgetId);
}

public static Intent getServiceIntent(Context context,int widgetId) {
    Intent intent = new Intent(context, WidgetService.class);
    intent.setData(Uri.parse(String.valueOf(widgetId)));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    return intent;
}
}`

WidgetProvider

...
    if (inbox.getBox.size() > 0) {
        Intent intent = WidgetService.getServiceIntent(context, widgetId);
        ...
        views.setRemoteAdapter(R.id.listView, intent);




        PendingIntent pendingIntent = PendingIntent.getService(context, 0,
                WidgetMailsAdapter.getItemFillInIntent(null, widgetId), PendingIntent.FLAG_UPDATE_CURRENT);


        views.setPendingIntentTemplate(R.id.listView, pendingIntent);
        return;
    }....
   }`

WidgetAdapter

public static Intent getItemFillInIntent(Box box, int widgetId) {



    Intent intent = new Intent(AppController.getInstance(), LaunchingService.class);

    if (box!= null) {
        LaunchingService.fillIntentForBox(intent, box, widgetId);
    }

    Log.d("Click","click");
    return intent;
}
}` 

LaunchingService

public class LaunchingService extends Service {


@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

...

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
        stopSelf();
        return START_NOT_STICKY;
    }
    Bundle bundle = intent.getBundleExtra(KEY_BUNDLE_KEY);
    if (bundle == null) {
        stopSelf();
        return START_NOT_STICKY;
    }
    int action = bundle.getInt(KEY_ACTION_ID);
   ...
    stopSelf();
    return START_NOT_STICKY;
}

...

public static void fillIntentForBox(Intent intent, Box box, int widgetId) {
    Bundle bundle = new Bundle();
    bundle.putInt(KEY_ACTION_ID, ACTION_BOX);
    bundle.putString(KEY_URI, box.getUri());
    bundle.putInt(KEY_WIDGET_ID, widgetId);
    intent.putExtra(KEY_BUNDLE_KEY, bundle);
}
android
service
android-listview
click
android-widget
asked on Stack Overflow Feb 13, 2020 by civoMT • edited Feb 13, 2020 by Alperen Kantarc─▒

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0