neqopa
neqopa

Reputation: 119

How can I pass an object to a widget

I am currently making an app that containing a widget. When placing the app a WidgetConfigure Activity opens where you can select an object out of a recycleViewer.

The object (Kitten) implements the parcelable and the recyleviewer is filled by an adapter class.

When the eventListner of that recyleviewer is triggered, the selected object must be passed to the widget since I need properties from that object in my widget.

I'm currently completely stuck and confused how I can pass an object to the widget. How can I pass an object to the widget?

Here is my code that will run in the eventListner in LongEventConfigureActivity:

private void makeWidget(Event myObj){

    // How I normally passing data to an activity/fragment

    //Intent i = new Intent();
    //Bundle b = new Bundle();
    //b.putParcelable(CONST_PARCELKEY, myObj);
    //i.putExtras(b);
    //i.setClass(this, ObjectDetailActivity.class);
    //startActivity(i);

    // Example of how to pass data to the widget
    final Context context = LongEventWidgetConfigureActivity.this;

    // When the button is clicked, store the string locally
    String widgetText = txtWidgetText.getText().toString();
    saveTitlePref(context, mAppWidgetId, widgetText);

    // It is the responsibility of the configuration activity to update the app widget
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    LongEventWidget.updateAppWidget(context, appWidgetManager, mAppWidgetId);

    // Make sure we pass back the original appWidgetId
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
    setResult(RESULT_OK, resultValue);
    finish();

}


@Override
public void onItemClick(Event e) {
    makeWidget(e);
}

Also I need to find a way when the user tapping this widget, a certain activity of my app will open that will receive that object.

Summery of the problem (I don't have the privilege to post an image yet)

Upvotes: 0

Views: 222

Answers (0)

Related Questions