• <i id='LAPeI'><tr id='LAPeI'><dt id='LAPeI'><q id='LAPeI'><span id='LAPeI'><b id='LAPeI'><form id='LAPeI'><ins id='LAPeI'></ins><ul id='LAPeI'></ul><sub id='LAPeI'></sub></form><legend id='LAPeI'></legend><bdo id='LAPeI'><pre id='LAPeI'><center id='LAPeI'></center></pre></bdo></b><th id='LAPeI'></th></span></q></dt></tr></i><div id='LAPeI'><tfoot id='LAPeI'></tfoot><dl id='LAPeI'><fieldset id='LAPeI'></fieldset></dl></div>
      <bdo id='LAPeI'></bdo><ul id='LAPeI'></ul>
    <tfoot id='LAPeI'></tfoot>
  • <small id='LAPeI'></small><noframes id='LAPeI'>

    <legend id='LAPeI'><style id='LAPeI'><dir id='LAPeI'><q id='LAPeI'></q></dir></style></legend>
      1. 通过单击小部件开始活动

        Start activity by clicking on widget(通过单击小部件开始活动)
        <tfoot id='aFJej'></tfoot>

          • <legend id='aFJej'><style id='aFJej'><dir id='aFJej'><q id='aFJej'></q></dir></style></legend>

            <small id='aFJej'></small><noframes id='aFJej'>

          • <i id='aFJej'><tr id='aFJej'><dt id='aFJej'><q id='aFJej'><span id='aFJej'><b id='aFJej'><form id='aFJej'><ins id='aFJej'></ins><ul id='aFJej'></ul><sub id='aFJej'></sub></form><legend id='aFJej'></legend><bdo id='aFJej'><pre id='aFJej'><center id='aFJej'></center></pre></bdo></b><th id='aFJej'></th></span></q></dt></tr></i><div id='aFJej'><tfoot id='aFJej'></tfoot><dl id='aFJej'><fieldset id='aFJej'></fieldset></dl></div>

                  <bdo id='aFJej'></bdo><ul id='aFJej'></ul>
                    <tbody id='aFJej'></tbody>
                  本文介绍了通过单击小部件开始活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Android 编程的新手,我尝试做一个小部件,它能够从 ISP 获取一些关于我的帐户的数据.有很多未知的事情怎么做,但我做了一些事情——我有一个带有配置活动的小部件,用户应该在其中输入登录名和密码.小部件将数据存储在 SharedPerferences 中,当需要更新小部件时,我使用服务启动 AsyncTask 以从 ISP 获取帐户数据.现在我想通过单击小部件来启动一个活动.我已经尝试了在此站点上找到的所有建议,并且小部件无法启动活动.我的小部件基于放置在这里的另一个小部件 https://github.com/Arturus/MetrikaWidget.我不明白我应该通过单击我的小部件来更改什么以及在哪里开始活动.谢谢.

                  I newbie at programming Android and I try to do a widget which has be able get some data from ISP about my account. There are a lot of unknown things how to do it, but I have did a few things - I've got a widget with configure activity, where user should type login and password. Widget stores the data in SharedPerferences, and when it's time to update widget I use a Service to start an AsyncTask to getting it from ISP an account data. Now I want to do start an activity by click on widget. I've tried all advice which I found on this site and widget can't start activity. My widget based on another widget which placed here https://github.com/Arturus/MetrikaWidget. I dont understand what and where I should change to start activity by clicking on my widget. Thanks.

                  更新:我的更新功能,我建议我应该放置 PendingIntent

                  UPDATE: My update function, where I suggest I should place PendingIntent

                  @Override
                  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
                  {
                      Log.d(TAG, "onUpdate");
                  
                      for (int appWidgetId : appWidgetIds)
                      {
                          updateAppWidget(context, appWidgetManager, appWidgetId);
                      }
                  
                      /* An updateAppWidget functions looks like as:
                  
                      Intent intent = new Intent(context, UpdateWidgetService.class);
                      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
                      context.startService(intent);
                      */
                  
                      Intent intent = new Intent(context, DetailedStatActivity.class);
                      PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
                  
                      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.layout);
                  
                      views.setOnClickPendingIntent(R.id.layout, pendingIntent);
                  
                      ComponentName componentName = new ComponentName(context.getPackageName(), WidgetProvider.class.getName());
                  
                      appWidgetManager.updateAppWidget(componentName, views);
                  }
                  

                  推荐答案

                  在您的小部件 AppWidgetProvider 类的 onUpdate() 方法中使用此代码段:

                  Use this snippet in onUpdate() method of your widget AppWidgetProvider class:

                  @Override
                  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
                      RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetlayout);
                      Intent configIntent = new Intent(context, Activity.class);
                  
                      PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);
                  
                      remoteViews.setOnClickPendingIntent(R.id.widget, configPendingIntent);
                      appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
                  }     
                  

                  这里 widgetlayout 是您的小部件布局的名称,而 R.id.widget 是它的父布局 ID.

                  Here widgetlayout is name of your widget layout and R.id.widget is it's parent layout id.

                  编辑:
                  现在,我看到了您添加到问题中的代码.您会这样做:

                  Edit:
                  Now,I see your code that you added to your question.You would to do:

                  PendingIntent.getActivity(context, 0, configIntent, 0);
                  

                  (那个开始的活动)而不是

                  (that start's activity) instead of

                  PendingIntent.getService(...);
                  

                  尝试启动服务.祝你好运.

                  that attempt to starts service.Good luck.

                  参考:
                  doityourselfandroid.com

                  helloandroid.com

                  这篇关于通过单击小部件开始活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)

                • <legend id='hDrxp'><style id='hDrxp'><dir id='hDrxp'><q id='hDrxp'></q></dir></style></legend>
                    <tbody id='hDrxp'></tbody>

                    1. <small id='hDrxp'></small><noframes id='hDrxp'>

                        <bdo id='hDrxp'></bdo><ul id='hDrxp'></ul>
                      • <i id='hDrxp'><tr id='hDrxp'><dt id='hDrxp'><q id='hDrxp'><span id='hDrxp'><b id='hDrxp'><form id='hDrxp'><ins id='hDrxp'></ins><ul id='hDrxp'></ul><sub id='hDrxp'></sub></form><legend id='hDrxp'></legend><bdo id='hDrxp'><pre id='hDrxp'><center id='hDrxp'></center></pre></bdo></b><th id='hDrxp'></th></span></q></dt></tr></i><div id='hDrxp'><tfoot id='hDrxp'></tfoot><dl id='hDrxp'><fieldset id='hDrxp'></fieldset></dl></div>

                          <tfoot id='hDrxp'></tfoot>