AdSense

Monday, 2 September 2013

Android - Widget "crashes" when the screen is being rotated

(Deutsche Version) The detailled error is: I have got an widget, when I click on it, I want it to open the corresponding app. This usually works. Sometimes, nothing happens when I click on it, mostly after turning the screen. The reason is: Several things (e.g. rotating the screen) do not call the onUpdate function but only the onReceive function. Because of having the following lines in the onUpdate


Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

remoteViews.setOnClickPendingIntent(R.id.button, pendingIntent);


the MainActivity was started. This did not happen when onReceive was called. Therefore, I had to add these lines to the onReceive function (I had to rename intent in localIntent because onReceive has a parameter Intent intent). Afterwards, everything worked fine.

No comments:

Post a Comment