设置活动不启动 [英] Settings Activity Not Launching

查看:124
本文介绍了设置活动不启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我有codeD:

So far i have coded:

public class WidgetActivity extends AppWidgetProvider
{    
    public void onReceive(Context context, Intent intent)
    {


        String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
        {

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_activity);

            Intent settingsIntent = new Intent(context, Info.class);
            PendingIntent clickPendIntent = PendingIntent.getActivity
                    (context, 0, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            views.setOnClickPendingIntent(R.id.Widget, clickPendIntent);





            AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views);


        }
    }
}

要没有成功我单击窗口小部件的屏幕上,并没有启动的时候。我缺少什么?

To no success i click the widget when its on screen and nothing launches. Am I missing anything?

推荐答案

把code,它确保了 PendingIntent 设置,在的OnUpdate()方法来代替。这可以确保一旦部件放置在主屏幕上的 PendingIntent 设置。

Put the code that makes sure the PendingIntent is set, in the onUpdate() method instead. This makes sure that as soon as the widget is put on the homescreen that the PendingIntent is set.

所以:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgets) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_activity);
    Intent intent = new Intent(context, Info.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.Widget, pendingIntent);

另外:

如果您也想拥有信息活动时,首先添加窗口小部件到主屏幕自动弹出,你应该阅读的这个Userful公司资料片的。

If you would also like to have the info Activity pop up automatically when first adding the widget to the home screen, you should read this userful piece of information.

这篇关于设置活动不启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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