Sub EditButton_Click
Dim btn As Button = Sender
Dim EditIntent As Intent
EditIntent.Initialize("com.zarhouni.messagingpa.EDIT_MESSAGE","")
EditIntent.AddCategory("android.intent.category.DEFAULT")
EditIntent.PutExtra("PendingMessage",PendingMessage)
StartActivity(EditIntent)
End Sub
In Activity A:
B4X:
Sub CopyExistingValuesToFields(InitIntent As Intent)
Dim SavedMessage As PendingMessage = InitIntent.GetExtra("PendingMessage")
LblDate.Text = SavedMessage.Date
LblTime.Text = SavedMessage.Time
TxtMessage.Text = SavedMessage.StrMessage
TxtTo.Text = SavedMessage.StrTo
End Sub
Sub Activity_Resume
Dim InitIntent As Intent = Activity.GetStartingIntent
If InitIntent <> Null Then
If InitIntent.HasExtra("PendingMessage") Then
CopyExistingValuesToFields(InitIntent)
End If
End If
End Sub
I can see while debugging that the Intent received by Activity A has no extras. In fact, all the member fields are null while only the Action URI is correctly set to com.zarhouni.messagingpa.EDIT_MESSAGE.
The InitIntent.HasExtra("PendingMessage") check doesn't evaluate to true.
Thanks Lucas. I know Intent is a bit of an overkill for this simple example, but I'm learning and wanted to learn how to use Intents to launch an Activity and pass information to it.
But can you elaborate how I will launch/display the Activity A in your case?
Thanks Lucas. I know Intent is a bit of an overkill for this simple example, but I'm learning and wanted to learn how to use Intents to launch an Activity and pass information to it.
But can you elaborate how I will launch/display the Activity A in your case?
CallSubDelayed (and its variants) launches the Activity called (A) after the current routine (ActivityB) terminates or adding Activity.Finish after the call statement.
CallSubDelayed (and its variants) launches the Activity called (A) after the current routine (ActivityB) terminates or adding Activity.Finish after the call statement.
Anyone please? I would really appreciate to know how intents work in B4A. I seem to be missing a small bit somewhere but can't quite figure out what it is
TDS: Mant thanks. Your mention of serializable forced me to look at the code. I was indeed storing the custom type instead of a String(which is what I wanted to do). So I changed the code to send a String in the intent extras and that worked.
That makes me wonder though. Can we not pass any object via Intent.PutExtra(strKey, object) ?