onUpdate() 메서드에서 일부 배열을 초기화 한 후 인 텐트와 버튼을 사용하여 onUpdate() 메서드에서 설정된 배열에 액세스 할 수없는 onReceive() 함수를 호출하려고합니다. 왜 그런가요? 이러한 배열은 객체 변수이며 public으로 선언됩니다. 내가 빠진 것이 있습니까?위젯 OnUpdate, onReceive
onReady() : 다음의 AppWidgetProvider의 API에서
package net.aerosoftware.widgettest;
import java.util.HashMap;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;
public class WidgetTest extends AppWidgetProvider {
public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
public HashMap<Integer, String> channelsImages;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
Log.e("UPDATE", "Start");
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
channelsImages = new HashMap<Integer, String>();
channelsImages.put(0, "one");
channelsImages.put(1, "two");
Intent active = new Intent(context, WidgetTest.class);
active.setAction(ACTION_WIDGET_RECEIVER);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
remoteViews.setOnClickPendingIntent(R.id.buttonclick, actionPendingIntent);
super.onUpdate(context, appWidgetManager, appWidgetIds);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
Log.e("UPDATE", "End");
}
@Override
public void onReceive(Context context, Intent intent)
{
Log.e("RECEIVE", "Start 2");
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER))
{
try
{
Log.e("SIZE", "Size Of channel array: "+channelsImages.size());
}
catch(Exception e)
{
Log.e("ON_RECIEVE_ERROR", " "+e.getMessage());
}
}
super.onReceive(context, intent);
Log.e("RECEIVE", "End");
}
}
"액세스 할 수 없음"이란 무엇을 의미합니까? 어떤 종류의 예외가 있습니까? 내용이 비어 있습니까? – DuduAlul
예, 널 포인터 예외입니다. – dfilkovi
질문에 코드를 추가하면 쉽게 작업 할 수 있습니다. – DuduAlul