如何通过小部件在图像上点击启动一个活动? [英] How to start an activity by the click on an image in widget?

查看:139
本文介绍了如何通过小部件在图像上点击启动一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Intent intent = new Intent( context, ColorConfigure.class);
Intent.putExtras(AppWidgetManager.EXTRA_APPWIDGET_ID, appwidgetId );
PendingIntent pi = PendingIntent.getActivity( context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews r = new RemoteViews( context.getPackageName(), R.layout. activity_widget);
r.setOnClickPendingIntent(R.I'd.pic, pic);

以上code是不工作的时间,即,当我开始了第一次的小部件,然后被小部件容易加载,但是当我去到开始从窗口小部件一个新的活动,然后什么也没有发生。
但每当我重新运行从Eclipse我的应用程序无需拆卸部件,然后我开始小部件没有任何毛刺运行​​成功。
我真的不知道什么样的问题是这一个?或者,如果任何人都可以通过发送我,从该活动启动按钮,一个新的活动部件的code来帮助我。

The above code isn't working for the time i.e., when I start the widget for the first time then widget gets loaded easily but when I go onto start a new activity from the widget then nothing happens. But whenever I re-run my app from the eclipse without removing the widget then my widget starts running successfully without any glitch. I don't really know what sort of problem is this one?? Or if anyone is able to help me by sending me the code of a widget that start a fresh activity from a button on that activity.

推荐答案

我的应用程序主屏幕小部件连我都面临着类似的问题。其中很相似,FB / Twitter的主屏幕小部件(显示更新,如果没有签名显示为你不signedin)。采用了android的服务来实现的。即使你并不需要的服务。你的情况你是不是叫manager.updateAppWidget(IDS,意见);

even i have faced similar problem for my app homescreen widget .which is very similar to fb/twitter homescreen widget(show updates if not signed show as "your not signedin").achieved using android service. even you don't need a service. in your case you are not calling manager.updateAppWidget(ids, views);

public class NFWidgetProvider extends AppWidgetProvider {

            @Override
            public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                    int[] appWidgetIds) {
    final Intent intent = new Intent(context, UpdateService.class);

            context.startService(intent);

                 }
}

Updateservice.class
//我的应用程序code..mention服务类的应用程序清单

Updateservice.class //my app code..mention service class app manifest

 public void onStart(Intent intent, int startId) {

AppWidgetManager manager = AppWidgetManager.getInstance(this);
        ComponentName thisWidget = new ComponentName(this,
                NFWidgetProvider.class);
        int[] ids = manager.getAppWidgetIds(thisWidget);
        final int N = ids.length;
        for (int i = 0; i < N; i++) {
            int awID = ids[i];

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

                Intent intent = new Intent(this, your intented class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                //views.setTextViewText(R.id.widgetcount, visitstext);
                PendingIntent pendingIntent = PendingIntent.getActivity(this,
                        0, intent, 0);

                views.setOnClickPendingIntent(R.id.widgetimage, pendingIntent);
manager.updateAppWidget(awID, views);
    }

这篇关于如何通过小部件在图像上点击启动一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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