I have a widget whose appearance will depend on information gained from the user in the configuration activity. However, I'm uncertain how (and in what section of code) to act on the information gained from the user in the config.
Here is the target functionality from the user's perspective: When the user creates the widget, the config activity prompts for a string (with an EditText). The user types it in and presses the submit button. The config activity goes away and the widget appears on the homescreen displaying the text the user entered. When the user touches the widget, the browser is opened and goes to a particular URL that is determined in part by the string the user entered. Here is what I have implemented so far: The config activity lets the user enter data and happily displays it to me as a Toast message. Then the config goes away as desired and the widget appears with the default widget icon. If you touch the widget, it goes to a hardcoded URL. (code below) My question: How do I "connect" the info from the config activity with the code that displays the widget itself? If I put the user's string in a putExtra of the intent sent in setResult(), where do I write the code to retrieve that extra? It seems like it ought to put it somewhere in the AppWidgetProvider code, but where? (Or is there a better way to do it?) Here are the relevant portions of my code: ------------------------ widget.java: ------------------------ public class Widget extends AppWidgetProvider { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { //Toast.makeText(context, "onReceive()", Toast.LENGTH_SHORT).show(); RemoteViews views = new RemoteViews(context.getPackageName (), R.layout.widget); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse ("http://www.cnn.com")); i.addCategory(Intent.CATEGORY_BROWSABLE); i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity")); PendingIntent pendingIntent = PendingIntent.getActivity (context, 0, i, 0); views.setOnClickPendingIntent(R.id.Widget, pendingIntent); AppWidgetManager.getInstance(context).updateAppWidget (intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views); } } } // end of widget.java ------------------------------------------------ WidgetConfiguration.java ------------------------------------------------ public class WidgetConfiguration extends Activity { EditText myEditText; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Intent intent = new Intent(); intent = getIntent(); Bundle extras = intent.getExtras(); int appWidgetId = extras.getInt (AppWidgetManager.EXTRA_APPWIDGET_ID); setResult(RESULT_CANCELED); // Set the view layout resource to use. setContentView(R.layout.config); // Find the EditText myEditText = (EditText)findViewById(R.id.txt_url); View.OnClickListener mOnClickListener = new View.OnClickListener () { public void onClick(View v) { Intent intent = new Intent(); intent = getIntent(); setResult(RESULT_OK, intent); Toast.makeText(getBaseContext(), myEditText.getText(), Toast.LENGTH_SHORT).show(); finish(); } }; // Bind the action for the submit button. findViewById(R.id.btn_urlSubmit).setOnClickListener (mOnClickListener); // If they gave us an intent without the widget id, just bail. if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); } } } //end of WidgetConfiguration.java -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en