Bug? Intent.PutExtra does not add object to Extras

Discussion in 'Bugs & wishlist' started by cimperia, Sep 4, 2015.

  1. cimperia

    cimperia Active Member Licensed User

    OS: Windows7 with .Net > 4.5
    B4A: 5.20

    There seems to be a bug with Intent.PutExtra. When I try to add my user defined Type (Category) to the intent Extras, it does not get added, and this failure happens silently.

    After adding my 3 Extras to the intent, I call Log(intent_.ExtrasToString) and the Category object is missing. When the called activity checks for the existence of the parameter, of course it is not there.

    Am I missing something?

    Sub Globals
    Type Category(Text As String, Notes As String, IsNew As Boolean)
    Dim btAddCategory As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Activity.AddView(btAddCategory, 50dip50dip100dip45dip)    
    End Sub

    Sub btAddCategory_Click
    Dim intent_ As Intent  
    Dim edit_category As Category

    'Populate Category Item
       edit_category.Text = 
       edit_category.Notes = 
    "Original Notes"
       edit_category.IsNew = 

    'Set up Intent    
    "cat", edit_category)

    'Check list of Extras, and cat is missing

       intent_.SetComponent(GetPackageName & 

    End Sub

    Sub GetPackageName As String
    Private r As Reflector
    Return r.GetStaticField("anywheresoftware.b4a.BA""packageName")
    End Sub
    CategoryManager Activity:

    Sub Activity_Create(FirstTime As Boolean)
    Dim sub_name As String
    Dim cat As Category
    Dim StartingIntent As Intent
      StartingIntent = 
       sub_name = StartingIntent.GetExtra(

    Log(StartingIntent.HasExtra("cat")) 'Always False
    'cat is always null
       cat = StartingIntent.GetExtra("cat")
    Log(cat = Null'Always true

    'CallSub2("", sub_name, cat)  
    End Sub
  2. corwin42

    corwin42 Expert Licensed User

    Objects put in the extras of an intent must be serializable. Custom defined types are not serializable.
    cimperia likes this.
  3. cimperia

    cimperia Active Member Licensed User


    It doesn't say anything about that in the B4A documentation though.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice