Hello,
Well, at last here is my solution: I convert my object array to string
array, put it in a bundle,
put the bundle in the intent extras, and create the pending intent: The
string array contains
all the fields of all the objects I need to pass. Then I undo them when I
receive them in the
application I launch.
--------------------------------------------------------------------------------------------------------------------------
Bundle b = new Bundle();
b.putStringArray("alarmMessages",
AlarmMessage.toStringArray(alarmMessages));
intent.putExtra("alarmMessages", b);
pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
---------------------------------------------------------------------------------------------------------------------------
Then inside my broadcast receiver:
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("AlarmReceiver", "received");
Intent i = new Intent(context, AlarmExpiredActivity.class);
i.putExtra("alarmMessages", intent.getBundleExtra("alarmMessages"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
-----------------------------------------------------------------------------------------------------------------------------
And then to reset the alarm inside my fired application:
Bundle b = getIntent().getBundleExtra("alarmMessages");
String[] alarmMessagesStr = b.getStringArray("alarmMessages");
this.alarmMessages = AlarmMessage.fromStringArray(alarmMessagesStr);
and then display the messages.
-------------------------------------------------------------------------------------------------------------------------------
Thanks,
Regards,
Feedback welcome,
John Goche
On Tue, Sep 27, 2011 at 9:52 AM, John Goche <[email protected]>wrote:
>
> Thanks TreKing for your approach,
>
> The only thing is I have to pass around an array of stuff, and the Intent
> interface only has:
>
> Bundle getBundleExtra(String name)
> Intent putExtra(String name, Bundle value)
> Intent putExtras(Bundle extras)
> Intent replaceExtras(Bundle extras)
>
> I have started implementing the approach given by TreKing...
> The problem I am having is I need to pass an array of objects (all of the
> same type).
> If I am going to pass this array in a bundle I need to generate a key for
> each element
> in the array while adding them to the bundle. Is this the way to go (or is
> using a DB better)?
>
> Thanks,
>
> John Goche
>
> On Sep 27, 4:00 am, TreKing <[email protected]> wrote:
>> > On Mon, Sep 26, 2011 at 2:40 PM, John Goche <
>> [email protected]>wrote:
>> >
>> >
>> > public interface Bundleable
>> > {
>> > public Bundle toBundle();
>> >
>> > public void fromBundle(Bundle b);
>> >
>> > }
>> >
>> > public class MyClass implements Bundleable
>> > {
>> > public Bundle toBundle()
>> > {
>> > Bundle b = new Bundle();
>> > // Fill b with data
>> > return b;
>> > }
>> >
>> > public void from Bundle(Bundle b)
>> > {
>> > // set properties from data in b
>> > }
>> >
>> > }
>> >
>> > // ...
>> >
>> > MyClass m = new MyClass();
>> > Intent i = new Intent();
>> > i.putBundleExtra("MyClass", m.toBundle());
>> >
>> > // ... Elsewhere
>> >
>> > Bundle b = intent.getBundleExtra("MyClass");
>> > MyClass m = new MyClass(b); // Constructor calls
>> > fromBundle(b);<android-developers%[email protected]>
>> <http://groups.google.com/group/android-developers?hl=en>
>>
>>
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en