Why won't Intent pass along the extras

by frizzo » Wed, 11 Mar 2009 13:45:47 GMT


Sponsored Links
 I have a class object that I want to pass from one screen to another.
So I made it inherit from Parcelable and added the following code to
my class:

public class ItemDescription implements Parcelable {
       /// property setters and getters

        public int describeContents() {
                // TODO Auto-generated method stub
                return 0;
        }

        public void writeToParcel(Parcel out, int flags) {
                out.writeInt(mData);
        }

        public static final Parcelable.Creator<ItemDescription> CREATOR = new
Parcelable.Creator<ItemDescription>() {
        public ItemDescription createFromParcel(Parcel in) {
            return new ItemDescription(in);
        }

        public ItemDescription[] newArray(int size) {
            return new ItemDescription[size];
        }
    };
}

In response to an event, I do kick off another screen (Intent) and put
extras into it:

        Intent mIntent = new Intent(v.getContext(), Item.class);

        Parcelable itemDesc = getItemDescription(preset);  // returns
ItemDescription
        mIntent.putExtra("com.vbrad.android.mystapp.item1", itemDesc);
        startActivity(mIntent);


In the onCreate event of this new activity, I attempt o retrieve the
contents of the itemDesc object in the following manner:


        Intent intent = getIntent();
        Parcelable p = intent.getParcelableExtra("com.vbrad.android.
mystapp.item1");
        ItemDescription itemDesc = (ItemDescription) p;

However, the itemDesc object is unpopulated - all the internal
variables are at default values (e.g. 0 for numeric types, null for
everything else).  It's like it was just created.

What am I missing here?

Thanks.


--~--~---------~--~----~------------~-------~--~----~



Why won't Intent pass along the extras

by Steven Farley » Wed, 11 Mar 2009 21:36:22 GMT


 I have done this succesfully with a Serializable object added with
Intent#putExtra(String, Serializable).  Is there some reason why
Parcelable is a better choice in your case?

++Steve



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Why won't Intent pass along the extras

by frizzo » Thu, 12 Mar 2009 13:26:03 GMT


 I have no idea whether it's a better choice or not.  I asked the
question here as to how to do it and was given Parcelable as the
answer.  I'll give it a try with serializable.




--~--~---------~--~----~------------~-------~--~----~



Why won't Intent pass along the extras

by frizzo » Thu, 12 Mar 2009 14:45:08 GMT


 Can you post an example by any chance?





--~--~---------~--~----~------------~-------~--~----~



Why won't Intent pass along the extras

by frizzo » Sat, 14 Mar 2009 12:35:11 GMT


 Serializable works.






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to align SurfaceView on Bottom ?

Hello,

i cant figure out whats wrong, and slowly this turnes into an
"showstopper" for me...
if i use a simple ImageView like this everything works fine (ImageView
is centered on bottom)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#269" android:gravity="center_horizontal"



<ImageView android:id="@+id/icon" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignParentBottom="true"
android:src="@drawable/icon" />




</RelativeLayout>



Using a SurfaceView instead just get layouted on top of the Screen,
why ?

Thanks for any advice,
Jens

-- 

2. Error in merging spannable objects

I began this topic on Stack Overflow but there was no answer. Please,
help. This is an absolute nonsense!

I want to merge 3 spannable objects. This code works fine:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Spannable s1 = new SpannableStringBuilder("bold");
             s1.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
0, s1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
             Spannable s2 = new SpannableStringBuilder("not");
             Spannable s3 = new SpannableStringBuilder("BOLD");
             s3.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
0, s3.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
             finishSpan = (Spanned) TextUtils.concat(s1,s2);
             finishSpan = (Spanned) TextUtils.concat(finishSpan,s3);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

or finishSpan = (Spanned) TextUtils.concat(s1,s2,s3);

I have the same code but when I merge 3 object,the result is wrong. I
have checked that the type of certain elements are true.
beginningOfModifiedSpannable is bold, selectionSpannable is
normal,endOfModifiedSpannable is bold But their merging is wrong. Only
the last part of the result string is bold. Why it happens?? I have
the same code above and it works well!
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 Spannable str = contentText.getText();
            Spannable selectionSpannable = new
SpannableStringBuilder(str, selectionStart, selectionEnd);
            StyleSpan[] ss = selectionSpannable.getSpans(0,
selectionSpannable.length(), StyleSpan.class);

            boolean exists = false;
            for (int i = 0; i < ss.length; i++) {
                if (ss[i].getStyle() == android.graphics.Typeface.BOLD)
{
                 selectionSpannable.removeSpan(ss[i]);
                    exists = true;
                }
            }

            if (!exists){
                str.setSpan(new
StyleSpan(android.graphics.Typeface.BOLD), selectionStart,
selectionEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            else {

             Spannable endOfModifiedSpannable = new
SpannableStringBuilder(str, selectionEnd,
contentText.getText().length());
             Spannable beginningOfModifiedSpannable = new
SpannableStringBuilder(str, 0, selectionStart);
             Spanned finishSpan = null;

             if(beginningOfModifiedSpannable.length() > 0) {

              if(endOfModifiedSpannable.length() > 0) {
               finishSpan = (Spanned)
TextUtils.concat(beginningOfModifiedSpannable,selectionSpannable);
               finishSpan = (Spanned)
TextUtils.concat(finishSpan,endOfModifiedSpannable);
                 }
              else {
               finishSpan = (Spanned)
TextUtils.concat(beginningOfModifiedSpannable,selectionSpannable);
              }

             }
             else {
              if(endOfModifiedSpannable.length() > 0) {
               finishSpan = (Spanned)
TextUtils.concat(selectionSpannable,endOfModifiedSpannable);
                     }
                  else {
                   finishSpan = selectionSpannable;
                  }
                 }
contentText.setText(finishSpan);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

!!
I repeat that I have checked that 3 parts are true. E.g. I have 3
parts: <b>Hel</b> lo,wor <b>ld</b>
!!

I have noticed that the first merging is right:

finishSpan = (Spanned)
TextUtils.concat(beginningOfModifiedSpannable,selectionSpannable);

It looks like Hello,wor

But the second is wrong:

finishSpan = (Spanned)
TextUtils.concat(finishSpan,endOfModifiedSpannable);

or this merging is wrong:
finishSpan = (Spanned)
TextUtils.concat(finishSpan,selectionSpannable,endOfModifiedSpannable);

And the result of wrong string is: Hello,wo<b>rld</b>

I also noticed that I any merging of 3 objects was wrong. I  tried to
change the order of words.

E.g. , First I was merging the second Spannable object and the third
one. The result was:
lo,wo<b>rld</b>
But when I merged this result with the first Spannable object, the
result was wrong again:
Hello,wo<b>rld</b>


!!!!!!!!!!!!!!
But the true result must be like this:

<b>Hel</b>lo,wo<b>rld</b>
!!!!!!!!!!!!!

Why it happens? I have been debugging 2 days and by the reason of
misunderstanding of an error I have made a hole in the wall by my head!

-- 

3. No sound output in speaker on AudioTrack.play

4. should i use HTML5 or android

5. AudioTrack Underrun Notifications?

6. Calculating screen coordiantes in augmented reality???

7. How to detect home screen icons pressing?