最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Problem with restarting widget on Xiaomi when app is closingopeningbackgrounding - Stack Overflow

programmeradmin4浏览0评论

I have an application with VebView and now I try to make a widget with message conversations. All is ok on my phone (Samsung), but on Xiaomi, every time when app is opening/closing/going to backgroud, system reset widget and load again. It doesn't look good. I found the problem is that every time system calls broadcast intent "android.intent.action.PACKAGE_CHANGED". I also found the problem arises when app is initializing OneSignal "OneSignal.initWithContext(this);". I was looking for the answer all internet but I cann't find anything about this problem. I would be very grateful for any opinion and help.

In my receiver

public class WidgetUpdateReceiver extends BroadcastReceiver {
    public WidgetUpdateReceiver() {
        super();
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction() != null && Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())) {
            String packageName = Objects.requireNonNull(intent.getData()).getSchemeSpecificPart();
            if ("com.myapp.name".equals(packageName)) {
                Log.d("WidgetUpdateReceiver", "Broadcast received");
            }
        }
    }
}

I tried to receive that broadcast, but it is protected by system... Only when I removed line "OneSignal.initWithContext(this);", widget were allright and didn't blink.

发布评论

评论列表(0)

  1. 暂无评论