Note that there are some explanatory texts on larger screens.

plurals
  1. POSend ArrayList<Object> from BroadCastReceiver to Activity
    primarykey
    data
    text
    <p><strong>Scenario:</strong></p> <ul> <li><p>I have an Alarm scheduled to run on a specified amount of time. Each time is executed, my BroadCastReceiver fires. </p></li> <li><p>In BroadCastReceiver I do all kind of checks and in the end it results a ArrayList of Notify class</p></li> <li><p>I display an Notification on the Statusbar</p></li> <li><p>When the user taps on a Notification, I display an Activity. I need in my Activity, the ArrayList to display it on views.</p></li> </ul> <p>Here is the sample code:</p> <pre><code>public class ReceiverAlarm extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ArrayList&lt;Notify&gt; notifications = new ArrayList&lt;Notify&gt;(); //do the checks, for exemplification I add these values notifications.add(new Notify("id1","This is very important")); notifications.add(new Notify("id2","This is not so important")); notifications.add(new Notify("id3","This is way too mimportant")); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); //init some values from notificationManager Intent intentNotif = new Intent(context, NotificationViewer.class); intentNotif.putParcelableArrayListExtra("list", notifications); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentNotif, 0); Notification notification = new Notification(icon, text, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notificationManager.notify(NOTIFICATION_ID, notification); } </code></pre> <p>And </p> <pre><code> public class NotificationViewer extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notification_viewer); ArrayList&lt;Notify&gt; testArrayList = null; Bundle b = getIntent().getExtras(); if (b != null) { testArrayList = b.getParcelableArrayList("list"); } } </code></pre> <p>And</p> <pre><code>public class Notify implements Parcelable { public Notify(Parcel in) { readFromParcel(in); } @SuppressWarnings("rawtypes") public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public Notify createFromParcel(Parcel in) { return new Notify(in); } public Notify[] newArray(int size) { return new Notify[size]; } }; @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(id); dest.writeString(text); } private void readFromParcel(Parcel in) { id = in.readString(); text = in.readString(); } public Notify(String id, String text) { super(); this.id = id; this.text = text; } /** The id. */ public String id; /** Notification text to be displayed. */ public String text; @Override public int describeContents() { return 0; } } </code></pre> <p>On testArrayList = b.getParcelableArrayList("list"); from NotificatioNActivity I get this error:</p> <blockquote> <pre><code>E/AndroidRuntime(14319): java.lang.RuntimeException: Unable to start activity </code></pre> <p>ComponentInfo{NotificationViewer}: java.lang.RuntimeException: Parcel android.os.Parcel@4050f960: Unmarshalling unknown type code 7602277 at offset 124</p> </blockquote> <p>As you can see, from qustions from SO I say that I needed to make my object Parcelable. Maybe I did something wrong in there but... I don't know how to fix it. What am I doing wrong ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload