Android - widget breaks after launcher reload/crash
I've made an Android home screen widget which displays some text and has 2 click listeners which I have working under normal operation, no problems. That is until HTC sense/launcher decides to reload, which it does most days. After the reload one of the click listeners stops working and can cause the widget to Force Close.
onClickListener 1 = starts an activity and passes it some text strings
onClickListener 2 = Triggers FORCE_WIDGET_UPDATE
After a launcher reload, the activity still trigures fine, but the widget update fails.
Here is the essence of the update code.
public static String updateString = "org.software.appname.FORCE_WIDGET_UPDATE";
public void onReceive(Context ctx, Intent intent){
showIntent=intent.getAction();
Log.d(TAG, showIntent);
if (updateString.equals(intent.getAction())){
Log.d(TAG, "onReceive, Force");
AppName.updateViews = new RemoteViews( ctx.getPackageName(),R.layout.main );
<Code to update text, update widget view and load new intents>
ComponentName me = new ComponentName( ctx, AppName.class );
AppWidgetManager.getInstance( ctx ).updateAppWidget( me, updateViews );
} else super.onReceive(ctx, intent);
I've tried moving the onRecieve call to the super class inside the if statement, but this causes the app to force close as soon you the widget is dropped onto the home screen.
I don't see anything in logcat when clicking the button, when I normally would, sometimes it force closes sometimes it doesn't. I can re-create the problem in the desktop simulator by force closing the stock launcher in application setting.
Thanks in advance for your help! :-)
Edit: I've tried changing things around by passing appWidgetIds[] in the intent and then triggering the onUpdate within onReceive, but this doesn't seem to do anything. I get the message in logcat to say it's registering the click, but it doens't seem to be triggering onUpdate.
public void onReceive(Context ctx, Intent intent){
AppWidgetManager appW开发者_开发技巧idgetManager = AppWidgetManager.getInstance(ctx);
int[] appWidgetIds = intent.getIntArrayExtra("appWidgetIds");
onUpdate(ctx, appWidgetManager, appWidgetIds);
Log.d(TAG, "onReceive log");
}
精彩评论