I am having trouble sending data (rows) from my activity to the appWidgetProvide class.
I have a method called updateWidget. This is caused by the widget’s settings being activated when the widget is first placed on the main screen. This method is also called by the onReceive method when it receives data from one of my actions, when the user enters data into this action.
Here is my problem: the widget is placed on the main screen with all the data in the right place. But when my activity sends onReceive data (using intentions and additional functions), the data does not arrive. I just get an empty string in extras.getString.
I used intentions to send data between actions before this, do I need to do something when I send data to the class that provides the widget? Or am I just stupid and skipping something obvious?
I have attached (what I think) the corresponding bits of code. Let me know if you need any clarification or any code.
Thanks for taking the time to read this and any help you can give,
Cheers Rakshak
onListItemClick in the widget customization class.
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Cursor note = mDbHelper.fetchNote(id); startManagingCursor(note); String title = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)); String text = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)); loadData(title); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK,resultValue); finish(); } void loadData(String title) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); SingleNote.updateWidget(this, appWidgetManager, mAppWidgetId, title); }
The purpose of sending data to onReceive (this is in one of my activity classes)
private void updateWidget() { Intent i = new Intent(this, SingleNote.class); i.setAction(SingleNote.UPDATE_ACTION); Toast.makeText(getApplicationContext(),mTitleText.getText()+"from the activity", Toast.LENGTH_SHORT).show();
}
My widget provides a class
public class SingleNote extends AppWidgetProvider { public static String UPDATE_ACTION = "ActionUpdateSinglenoteWidget"; private static NotesDbAdapter mDbHelper; public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length;