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

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

        Android Widget 在更新期间显示奇怪的图像

        时间:2023-09-09
          <tbody id='px5Wj'></tbody>

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

            <legend id='px5Wj'><style id='px5Wj'><dir id='px5Wj'><q id='px5Wj'></q></dir></style></legend>

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

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

              • <tfoot id='px5Wj'></tfoot>

                1. 本文介绍了Android Widget 在更新期间显示奇怪的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我这里有一个奇怪的...我有一台运行 android 1.5 的带有 Nextel 的摩托罗拉 i1

                  I have a strange one here... I have a Motorola i1 with Nextel running android 1.5

                  我有一个安卓小部件.当我开始运行更新此小部件的服务时,我会看到来自另一个小部件的图像(启动 DC 联系人)

                  I have an android widget. When I start running the Service that updates this Widget I see an image from another widget (Launch DC Contact)

                  它在我的小部件的位置显示此图像,但是当我的小部件更新"完成时,它会替换为我的小部件布局.

                  It shows this image in my widget's location but when "update" of my widget is done it is replaced with the layout I have for my widget.

                  就好像有一个小部件图像缓存,它会从那里显示内容,直到我的小部件更新完成.

                  It is as if there is a cache of widget images and it shows stuff from there until my widget's update is done.

                  如果我的更新需要很长时间,那么用户可以在 2-3 秒内看到这个奇怪的图像.

                  If my update takes long then user can see this strange image for 2-3 secs.

                  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                              int[] appWidgetIds) {
                          Log.d(TAG, "Enter onUpdate");
                          final int N = appWidgetIds.length;
                  
                          for (int i = 0; i < N; i++) {
                              int widgetId = appWidgetIds[i];
                              RemoteViews views = new RemoteViews(context.getPackageName(),
                                      R.layout.widget_initial_layout);
                              Intent intent = new Intent(context, MainActivity.class);
                              PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                                      intent, 0);
                              views.setOnClickPendingIntent(R.id.WidgetLayout, pendingIntent);
                              views.setTextViewText(R.id.NEWCountTextView, Integer.toString(NEWC));
                              views.setTextViewText(R.id.ACKCountTextView, Integer.toString(ACKC));
                              views.setTextViewText(R.id.PKUCountTextView, Integer.toString(PKUC));
                              views.setTextViewText(R.id.PODCountTextView, Integer.toString(PODC));
                              if (errorMessage.contentEquals("")) {
                                  errorMessage = (new Date()).toString();
                                  views.setTextColor(R.id.LastUpdatedTextView, Color.BLACK);
                              } else {
                                  views.setTextColor(R.id.LastUpdatedTextView, Color.RED);
                              }
                              views.setTextViewText(R.id.LastUpdatedTextView, errorMessage);
                              appWidgetManager.updateAppWidget(widgetId, views);
                          }
                          Log.d(TAG, "Exit onUpdate");
                      }
                  
                  public void onReceive(Context context, Intent intent) {
                      Log.d(TAG, "Enter onReceive");
                      String action = intent.getAction();
                      if (action.contentEquals("android.appwidget.action.APPWIDGET_UPDATE")) {
                          Bundle extras = intent.getExtras();
                          if (extras != null) {
                              NEWC = extras.getInt("NEWCOUNT");
                              ACKC = extras.getInt("ACKCOUNT");
                              PKUC = extras.getInt("PKUCOUNT");
                              PODC = extras.getInt("PODCOUNT");
                              errorMessage = extras.getString("ERRORMESSAGE");
                          }
                      }
                  

                  super.onReceive(上下文,意图);Log.d(TAG, "接收时退出");}这是布局

                  super.onReceive(context, intent); Log.d(TAG, "Exit onReceive"); } here is the layout

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout 
                      xmlns:android="http://schemas.android.com/apk/res/android"
                      android:id="@+id/WidgetLayout" 
                      android:layout_height="wrap_content" 
                      android:layout_width="wrap_content"
                      android:gravity="top"
                      android:orientation="vertical"
                      android:background="@drawable/bg"
                      >
                  
                      <TextView 
                          android:text="ORDERS" 
                          android:id="@+id/TextView01" 
                          android:layout_width="fill_parent" 
                          android:layout_height="wrap_content"
                          android:textSize="25dip"
                          android:gravity="top|center"
                          android:textColor="#ffff00"
                          android:textStyle="bold"
                          />
                  
                      <TextView 
                          android:text="" 
                          android:id="@+id/TextView01" 
                          android:layout_width="fill_parent" 
                          android:layout_height="6dip"
                          android:gravity="top|center"
                          android:background="#0000ff"
                          />
                  
                      <LinearLayout 
                          xmlns:android="http://schemas.android.com/apk/res/android"
                          android:id="@+id/LinearLayout02" 
                          android:layout_height="wrap_content" 
                          android:layout_width="fill_parent"
                          android:gravity="top|center"
                          android:orientation="horizontal"        
                          >
                          <LinearLayout 
                              xmlns:android="http://schemas.android.com/apk/res/android"
                              android:id="@+id/CountsLinearLayout" 
                              android:layout_height="fill_parent" 
                              android:layout_width="wrap_content"
                              android:gravity="top"
                              android:orientation="vertical"
                              >
                              <TextView 
                                  android:text="NEW" 
                                  android:id="@+id/TextView11" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                  
                                  />
                              <TextView 
                                  android:text="" 
                                  android:id="@+id/NEWCountTextView" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                                  />
                          </LinearLayout>
                  
                          <LinearLayout 
                              xmlns:android="http://schemas.android.com/apk/res/android"
                              android:id="@+id/LinearLayout04" 
                              android:layout_height="fill_parent" 
                              android:layout_width="wrap_content"
                              android:gravity="top"
                              android:orientation="vertical"
                              >
                              <TextView 
                                  android:text="ACK" 
                                  android:id="@+id/TextView21" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                  
                                  />
                              <TextView 
                                  android:text="" 
                                  android:id="@+id/ACKCountTextView" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                                  />
                          </LinearLayout>
                  
                          <LinearLayout 
                              xmlns:android="http://schemas.android.com/apk/res/android"
                              android:id="@+id/LinearLayout05" 
                              android:layout_height="fill_parent" 
                              android:layout_width="wrap_content"
                              android:gravity="top"
                              android:orientation="vertical"
                              >
                              <TextView 
                                  android:text="PKU" 
                                  android:id="@+id/TextView31" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                                  />
                              <TextView 
                                  android:text="" 
                                  android:id="@+id/PKUCountTextView" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                                  />
                          </LinearLayout>
                  
                          <LinearLayout 
                              xmlns:android="http://schemas.android.com/apk/res/android"
                              android:id="@+id/LinearLayout06" 
                              android:layout_height="fill_parent" 
                              android:layout_width="wrap_content"
                              android:gravity="top"
                              android:orientation="vertical"
                              >
                              <TextView 
                                  android:text="POD" 
                                  android:id="@+id/TextView41" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                                  />
                              <TextView 
                                  android:text="" 
                                  android:id="@+id/PODCountTextView" 
                                  android:layout_width="75dip" 
                                  android:layout_height="wrap_content"
                                  android:textSize="25dip"
                                  android:gravity="center"
                                  android:textColor="#000000"
                                  android:textStyle="bold"
                                  />
                          </LinearLayout>
                  
                  
                      </LinearLayout>
                  
                      <TextView 
                          android:text="" 
                          android:id="@+id/TextView01" 
                          android:layout_width="fill_parent" 
                          android:layout_height="6dip"
                          android:gravity="bottom|center"
                          android:background="#0000ff"
                          />
                  
                      <TextView 
                          android:text="" 
                          android:id="@+id/LastUpdatedTextView" 
                          android:layout_width="fill_parent" 
                          android:layout_height="wrap_content"
                          android:textSize="15dip"
                          android:gravity="center"
                          android:textColor="#000000"
                          android:textStyle="bold"
                          />                  
                  </LinearLayout>
                  

                  你见过这样的事吗?

                  谢谢

                  推荐答案

                  我在我的小部件中遇到了与您描述的完全相同的问题,并且搜索了很多解决方案但找不到任何解决方案.我最终做的是某种在我的情况下似乎可以正常工作的解决方法.我所做的是以下内容,而不是直接从 onUpdate() 方法更新小部件,我启动了一个服务来处理更新然后杀死自己.这在模拟器和更新期间小部件卡住的设备上解决了它.这是一个示例代码:

                  I had the exact same issue in my widget as you described and searched a lot for a solution and couldn't find any. What I ended up doing is some kind of workaround that seems to work fine in my case. What i did is the following, instead of updating the widgets directly from the onUpdate() method, I started a service that handled the update then killed itself. This solved it on the emulator and on a device that had the widget stuck during update. Here's a sample code:

                  AppWidgetProvider:

                  The AppWidgetProvider:

                  @Override
                  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
                      context.startService(new Intent(context, WidgetService.class));
                  }
                  

                  服务:

                  @Override
                  public void onStart(Intent intent, int startId) {
                      started(intent);
                  }
                  
                  @Override
                  public int onStartCommand(Intent intent, int flags, int startId) {
                      started(intent);
                      return START_STICKY;
                  }
                  
                  
                  private void started(Intent intent) {
                      //update here the widgets
                      Context context = getApplicationContext();
                      updateWidgets(context);
                      stopSelf();//killing the service
                  }
                  
                  private void updateWidgets(Context context) {
                      AppWidgetManager appmanager = AppWidgetManager.getInstance(context);
                      ComponentName cmpName = new ComponentName(context, widgetClass);
                      int[] widgetIds = appmanager.getAppWidgetIds(cmpName);
                      RemoteViews rView = new RemoteViews(context.getPackageName(), layoutId);
                      for (int wid : widgetIds) {
                          //all updates here
                          rView.setTextViewText(tvId, desc);
                          appmanager.updateAppWidget(wid, rView);
                      }
                  }
                  

                  请注意为什么此解决方法可以解决问题,但好处是确实可以希望这会有所帮助

                  Note sure why this workaround solves the issue, but the good thing is that it does Hope this helps

                  这篇关于Android Widget 在更新期间显示奇怪的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:主屏幕小部件上的 iOS 时钟动画 下一篇:如何在小部件中使用列表视图?

                  相关文章

                      • <bdo id='8nTTN'></bdo><ul id='8nTTN'></ul>
                    1. <legend id='8nTTN'><style id='8nTTN'><dir id='8nTTN'><q id='8nTTN'></q></dir></style></legend>

                      <small id='8nTTN'></small><noframes id='8nTTN'>

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

                      <tfoot id='8nTTN'></tfoot>