I have a widget with a few buttons. 
I want one button to open preferences, and the second to start an 
AlarmManager according to the preferences that have been set. 
A click of either button on the widget will go the same activity, but I wish 
to distinguish between the clicks via extra information. And I set some 
extra information in my intent. 
Then in my activity I check for this extra information, but I can't ever 
seem to get it as not null. 
Am I doing something wrong here? 

(I can't copy over from my source directory so the code might be 
slightly erroneous)

// Setting up the intent from the widget onUpdate function
Intent intent = new Intent( context, Preferences.class ); 
intent.setAction( ACTION_WIDGET_PREFERENCES ); 
PendingIntent pendingIntent = PendingIntent.getActivity( context, 0, intent, 
0 ); 
intent.putExtra( "timerSetup", false ); 
remoteViews.setOnClickPendingIntent( R.id.button_settings, pendingIntent ); 


...

// And in my onCreate of my activity:
Bundle = getIntent().getExtras(); 
try {
  if ( extras.isEmpty() )
    Log.i( "Preferences.onCreate", "Bundle empty" ); 
} catch ( Exception e ) {
  Log.w( "Preferences.onCreate", "extras.isEmpty() threw" ); 
}


And each time I press the button isEmpty throws. 

I also tried

getIntent().getBooleanExtra( "timerSetup", false ); 

and while it doesn't throw, it always seems to return the default value I 
provide (even if I pass an integer in instead). 

How can I pass data from a widget to an activity correctly? 

All advice appreciated.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to