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?

    Code:
    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)
       btAddCategory.Initialize(
    "btAddCategory")
       
    Activity.AddView(btAddCategory, 50dip50dip100dip45dip)    
    End Sub


    Sub btAddCategory_Click
       
    Dim intent_ As Intent  
       
    Dim edit_category As Category

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

       
    'Set up Intent    
       intent_.Initialize("""")
       intent_.PutExtra(
    "FromActivity""CategoryManager")    
       intent_.PutExtra(
    "cat", edit_category)
       intent_.PutExtra(
    "Sub_To_Call""InsertCategory")    

       
    'Check list of Extras, and cat is missing
       Log(intent_.ExtrasToString)

       intent_.SetComponent(GetPackageName & 
    "/.categorymanager")

       
    StartActivity(intent_)
       
    End Sub

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

    Code:
    Sub Activity_Create(FirstTime As Boolean)
      
    Dim sub_name As String
       
    Dim cat As Category
       cat.Initialize
      
      
    Dim StartingIntent As Intent
      StartingIntent = 
    Activity.GetStartingIntent
      
       sub_name = StartingIntent.GetExtra(
    "Sub_To_Call")

       
    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

    Thanks.

    It doesn't say anything about that in the B4A documentation though.
     
Loading...
  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