安卓onEnabled / onDisabled从来没有所谓的 [英] Android onEnabled/onDisabled never called

查看:805
本文介绍了安卓onEnabled / onDisabled从来没有所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,触发onEnabled和onDisabled的AppWidgetReciever的方法。我有指定的操作,我也登录onRecieve方法的每一个动作,但只有两个动作我得到的是APPWIDGET_UPDATE和APPWIDGET_DELETED。我用Google搜索了这个解决方案,但不幸的是没有发现。这是我的code:

I'm having a problem with triggering of the onEnabled and onDisabled methods of the AppWidgetReciever. I have the actions specified, I also log every action in onRecieve method, but the only two actions I get are "APPWIDGET_UPDATE" and "APPWIDGET_DELETED". I have googled for this solution, but unfortunately found none. Here is my code:

清单的一部分:

<receiver android:name=".ScheduleWidgetProvider" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
                <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="android.appwidget.action.APPWIDGET_DELETED" /> 
            </intent-filter>
            <meta-data android:name="android.appwidget.provider"
                android:resource="@xml/provider_xml" />
        </receiver>

Provider_xml:

Provider_xml:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="180dp"
    android:minHeight="40dp"
    android:updatePeriodMillis="60000"
    android:initialLayout="@layout/widget_layout"
    android:configure="org.zivkovic.schedule.ConfigurationActivity"
    >
</appwidget-provider>

ScheduleWidgetProvider:

ScheduleWidgetProvider:

public class ScheduleWidgetProvider extends AppWidgetProvider {
    {
        Log.w("Schedule", "ScheduleWidgetProviderRequested");
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.w("Schedule", "On recieve " + intent.getAction());
        super.onReceive(context, intent);
    }

    @Override
    public void onEnabled(Context context) {
        Log.w("Schedule", "OnEnabled called");
        ...
        super.onEnabled(context);
    }

    @Override
    public void onDisabled(Context context) {
        Log.w("Schedule", "OnDisabled called");

        ...

        super.onDisabled(context);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int i = 0; i < appWidgetIds.length; i++) {
            ....
        }
        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

}

任何帮助是AP preciated。谢谢!

Any help is appreciated. Thanks!

推荐答案

好了,从手机中删除我的应用程序并获得成功。不明白为什么卸载固定它。对于具有任何人同样的问题,卸载并重新安装应用程序。

Okay, removing my app from the phone did the trick. Can't understand why uninstall fixed it. With anyone having the same problem, uninstall and reinstall your app.

这篇关于安卓onEnabled / onDisabled从来没有所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆