You will need to use two distinct Intents, ones that route to the same
activity but differ by something more than just the extras. For
example, on one, add an action string that you won't be using. It will
not affect the routing (you're specifying the class name, which trumps
everything else).

On Thu, Apr 28, 2011 at 10:45 AM, Niall <twom...@gmail.com> wrote:
> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 3.0 Programming Books: http://commonsware.com/books

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

Reply via email to