Widget From Beginning
I am trying to develop an Android widget. Right now I can open an Activity when the widget is created, by the way; what I really need is that the first time the widget is clicked configure the action to do when the widget is clicked.
Anyone have any idea on 开发者_StackOverflow社区how to do it? Thanks in advance
Yes, this worked for me but the main problem now is know how to change the action that the button has to do, depending on the result of the configuration activity, I dont know if I explain my self, I will post some code to clarify the idea. If the button A is pressed i want to do this:
RemoteViews r = new RemoteViews(getApplicationContext().getPackageName(),R.layout.main);
Intent configIntent = new Intent(getApplicationContext(), ClickOneActivity.class);
configIntent.setAction(ButtonWidget.ACTION_WIDGET_CONFIGURE);
configIntent.putExtra("execute", "execute");
If the button B is pressed I want to do this:
RemoteViews r = new RemoteViews(getApplicationContext().getPackageName(),R.layout.main);
Intent configIntent = new Intent(getApplicationContext(), ClickOneActivity.class);
configIntent.setAction(ButtonWidget.ACTION_WIDGET_CONFIGURE);
configIntent.putExtra("execute", "no-execute");
And finally:
PendingIntent cint = PendingIntent.getActivity(getApplicationContext(), 0, configIntent, 0);
r.setOnClickPendingIntent(R.id.button_one, cint);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
setResult(RESULT_OK, resultValue);
finish();
Make a settings activity and open it on the first click. Also, put a flag to the shared prefernces, that first click has been already done. If there is no such flag, then the click is really first.
精彩评论