English 中文(简体)
Simple Problem With Intent Extras
原标题:

Posted: Mon Nov 30, 2009 5:08 pm Post subject: Simple Problem With Intent Extras Hello,

I m working on an app widget for the home screen. I m trying to make it so when a user taps on the widget it changes the data being displayed in the widget. However, I m also allowing multiple instances of widgets open with different data. So in order to tell my method which widget to update, I m adding an extra to the intent that is launched to change the data.

Here s the intent I have: Java:

Intent changeData = new Intent("com.tonycosentini.mintdroid.CHANGE_DATA"); 
changeData.putExtra("widget_id", currentWidgetId); 
PendingIntent changeDataPendingIntent = PendingIntent.getBroadcast(this, 0, changeData, 0); 
//This will return the correct value, but if I call it in my onreceive() method it won t.
Log.v(TAG, "stored id is: " + changeData.getIntExtra("widget", 0);

This correctly stores the widget id, but when the change data method is called, the widget id that is read from the intent is the first widget instance. That is, there is is a for loop that generates all of the widgets and no matter what widget you tap, the widget id that is recieved is always the first widget id in the first widget.

Anyone have an idea on how to solve this? Hopefully I didn t word it too poorly.

Thanks for reading, Tony

最佳回答

This is a known issue with PendingIntents; when Android compares PendingIntents it does not compare Intent extras, so you can t schedule the same basic Intent multiple times with only different extras. Right now, you can only solve this by making the Intent unique in some way other than extras, such as adding extra information to the Intent data.

There s a little bit of discussion of this on the Google Android Group: http://groups.google.com/group/android-developers/browse_thread/thread/81100da6ddb21136

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签