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

        <bdo id='EiZhB'></bdo><ul id='EiZhB'></ul>

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

        为什么小部件在重新启动后不起作用?

        时间:2023-09-09
          <tbody id='JCmBh'></tbody>
          <bdo id='JCmBh'></bdo><ul id='JCmBh'></ul>

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

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

                <tfoot id='JCmBh'></tfoot>

                  <legend id='JCmBh'><style id='JCmBh'><dir id='JCmBh'><q id='JCmBh'></q></dir></style></legend>
                  本文介绍了为什么小部件在重新启动后不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个简单的小部件,当我点击它时,它应该会打开我的活动,它可以工作,但重启后它就不能工作了.我必须删除然后再次将小部件添加到我的主屏幕,因为当我单击小部件时,小部件没有响应并且没有打开我的活动.那么问题出在哪里?

                  I have this simple widget and when I click on it, it should open my activity, it works, but it doesn't work after reboot. I must delete and then again add widget to my homescreen, because when I click on widget widget doesn't respond and doesn't open my activity. So where is the problem?

                  代码:

                  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
                          final int N = appWidgetIds.length;
                  
                          for(int i=0; i<N; i++){
                              int appWidgetId = appWidgetIds[i];
                  
                              context.startService(new Intent(context, WidgetService.class));
                  
                              Intent intent = new Intent(context, WidgetDialog.class);
                              PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
                  
                              RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
                              views.setOnClickPendingIntent(R.id.layout_widget, pendingIntent);
                  
                              appWidgetManager.updateAppWidget(appWidgetId, views);
                          }
                      }
                  
                      @Override
                      public void onEnabled(Context context){
                          context.startService(new Intent(context, WidgetService.class));
                      }
                  
                      @Override
                      public void onDisabled(Context context){
                          context.stopService(new Intent(context, WidgetService.class));
                      }
                  

                  推荐答案

                  重启后你会调用 OnEnabled 而不是 onUpdate 所以将代码从 onUpdate 移到一个单独的方法中,然后调用该方法从 onEnabled 更新所有小部件

                  After reboot you OnEnabled is called instead of onUpdate so move the code from onUpdate into a separate method and then call that method to update all widgets from onEnabled

                  这篇关于为什么小部件在重新启动后不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:AppWidgetProvider 问题 下一篇:Android Widget:预览图像大小

                  相关文章

                    <bdo id='3RHrS'></bdo><ul id='3RHrS'></ul>

                • <tfoot id='3RHrS'></tfoot>
                  1. <small id='3RHrS'></small><noframes id='3RHrS'>

                    <legend id='3RHrS'><style id='3RHrS'><dir id='3RHrS'><q id='3RHrS'></q></dir></style></legend>

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