简体   繁体   中英

Sending data from Configuration Activity to AppWidget

I've got a widget and configuration Activity for this widget. The question is how to send data from configuration Activity to widget? I've tried using intents with putExtra(), but how to catch intent in the widget? Are there any patterns?

This is what I have for now:

@Override
public void onClick(View v){
bd = new DateTime(  
datePick.getYear(), 
datePick.getMonth()+1, 
datePick.getDayOfMonth(),  
timePick.getCurrentHour(),  
timePick.getCurrentMinute());

//this is first variant             
Intent sendDateIntent = new Intent(context, WidgetActivity.class);
sendDateIntent.putExtra("birthDate", bd.getMillis());

//this is second variant
Intent resultValue = new Intent();
resultValue.putExtra("birthDate", bd.getMillis());
setResult(RESULT_OK, resultValue);
finish();
}
}

Here is the link to the developer docs .

`Additionally, you can implement an App Widget configuration Activity. This is an optional Activity that launches when the user adds your App Widget and allows him or her to modify App Widget settings at create-time.

The following sections describe how to setup each of these components.`

Everything you need is detailed here . (note click on this link for a step by step procedure to do exactly what you want. Do I need to copy the docs to this website to get accepted?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM