刷新窗口小部件时是否每个对象都被销毁?

时间:2015-02-25 20:36:45

标签: android android-widget

我的小部件看起来像这样:

public class WidgetMain extends AppWidgetProvider {

public LocationListenerClass locationListener = null;
private static final String WIDGET_CLICKED    = "widgetClickTest";



  @Override
public void onEnabled(Context context) {

    super.onEnabled(context);
     Intent intent = new Intent(context,WidgetMain.class);
     intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);

     int[] ids = {R.xml.widget_provider};
     intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
     context.sendBroadcast(intent);
}





@Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
      int[] appWidgetIds) {
    if(locationListener == null){

        Log.d("onUpdate", "locationIsNull=true");
    }
    Log.d("onUpdate", "isCalled=true");

    }
  }





@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    super.onReceive(context, intent);
    if(WIDGET_CLICKED.equals(intent.getAction())){
        if(locationListener != null){
        locationListener.getSingleUpdate();
        }
    }
}





@Override
public void onDeleted(Context context, int[] appWidgetIds) {
    // TODO Auto-generated method stub
    super.onDeleted(context, appWidgetIds);
    locationListener.destroy();
}

}

那么, 当我运行时(以及当它接收更新广播时)我的应用程序我在调试日志中得到了locationIsNull = true和isCalled = true,所以我的问题是。是否在更新小部件之间销毁了对象?

1 个答案:

答案 0 :(得分:2)

您的流程可以并且通常会在应用小部件更新之间终止。新进程将不包含旧进程中的任何静态数据成员。