Skip to content Skip to sidebar Skip to footer

Passing Data From Widget To App

I'm developing a widget for my app and I'd like to pass specific data from the widget to the app. The user can add multiple versions of the widget and I need to detect which widge

Solution 1:

first of all - your application not really close when you pressing back until returning to home screen. it's just that no activities from your application exists in this stage. I think it's very important to know that, in case you didn't...

about your problem: you are trying to launch activity from the widget with the FLAG_ACTIVITY_CLEAR_TOP, that it definition:

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

that means that if your Main activity already running in forground, then when you start the activity from the widget - all other activities on top of this Main activity will be removed from stack, and Main will resume and get into to Activity.onNewIntent(intent) callback.

that's why you don't see the data - because the activity don't restart with the new intent, but only get into the onNewIntent(intent) with the new intent you sent.

I'm sure that if you'll put a break point in the onNewIntent(intent) method - you'll see that the intent you sent is delivered there, with all the extra's data.

another problem with your code: check the definition of the Intent.putExtras(boundle) method:

Add a set of extended data to the intent. The keys must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

it seems like you don't call your key prefix according to the rules. that's why it's null.

hope it helped you.

Post a Comment for "Passing Data From Widget To App"