H Haris Hafeez Active Member Licensed User Longtime User Jul 27, 2014 #1 Hi All, So I've got a couple of Activities. Activity A - Allows users to create and saved messages Activity B - Lists all the messages with the ability to edit each stored message. I want the edit button on each of the items shown on Activity B to launch Activity A and pass the stored message. I have the following code: Manifest: (NewScheduledMessageActivity is Activity A for reference) Code: Copy AddActivityText(NewScheduledMessageActivity, <intent-filter> <action android:name="com.zarhouni.messagingpa.EDIT_MESSAGE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>) In Activity B: Code: Copy 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: Code: Copy 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. What is the small thing I am missing here? Thanks!
Hi All, So I've got a couple of Activities. Activity A - Allows users to create and saved messages Activity B - Lists all the messages with the ability to edit each stored message. I want the edit button on each of the items shown on Activity B to launch Activity A and pass the stored message. I have the following code: Manifest: (NewScheduledMessageActivity is Activity A for reference) Code: Copy AddActivityText(NewScheduledMessageActivity, <intent-filter> <action android:name="com.zarhouni.messagingpa.EDIT_MESSAGE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>) In Activity B: Code: Copy 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: Code: Copy 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. What is the small thing I am missing here? Thanks!
LucaMs Expert Licensed User Longtime User Jul 27, 2014 #2 You don't need that all work Create a sub in ActivityA that can receive the messag, for example: Public Sub ReceiveMsg(Msg As String); then, from ActivityB, when a message is selected, use: CallSubDelayed2(ActivityA, ReceiveMsg, SelectedMsg) Upvote 0
You don't need that all work Create a sub in ActivityA that can receive the messag, for example: Public Sub ReceiveMsg(Msg As String); then, from ActivityB, when a message is selected, use: CallSubDelayed2(ActivityA, ReceiveMsg, SelectedMsg)
H Haris Hafeez Active Member Licensed User Longtime User Jul 27, 2014 #3 LucaMs said: You don't need that all work Create a sub in ActivityA that can receive the messag, for example: Public Sub ReceiveMsg(Msg As String); then, from ActivityB, when a message is selected, use: CallSubDelayed2(ActivityA, ReceiveMsg, SelectedMsg) Click to expand... 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? Upvote 0
LucaMs said: You don't need that all work Create a sub in ActivityA that can receive the messag, for example: Public Sub ReceiveMsg(Msg As String); then, from ActivityB, when a message is selected, use: CallSubDelayed2(ActivityA, ReceiveMsg, SelectedMsg) Click to expand... 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?
LucaMs Expert Licensed User Longtime User Jul 27, 2014 #4 Haris Hafeez said: 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? Click to expand... CallSubDelayed (and its variants) launches the Activity called (A) after the current routine (ActivityB) terminates or adding Activity.Finish after the call statement. Upvote 0
Haris Hafeez said: 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? Click to expand... CallSubDelayed (and its variants) launches the Activity called (A) after the current routine (ActivityB) terminates or adding Activity.Finish after the call statement.
H Haris Hafeez Active Member Licensed User Longtime User Jul 27, 2014 #5 LucaMs said: CallSubDelayed (and its variants) launches the Activity called (A) after the current routine (ActivityB) terminates or adding Activity.Finish after the call statement. Click to expand... Thanks Lucas. Any idea about why the Intent mechanism is not working for me? Cheers. Upvote 0
LucaMs said: CallSubDelayed (and its variants) launches the Activity called (A) after the current routine (ActivityB) terminates or adding Activity.Finish after the call statement. Click to expand... Thanks Lucas. Any idea about why the Intent mechanism is not working for me? Cheers.
H Haris Hafeez Active Member Licensed User Longtime User Jul 27, 2014 #6 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 Upvote 0
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
thedesolatesoul Expert Licensed User Longtime User Jul 27, 2014 #7 What is PendingMessage? Is it serializable? Try passing a string, and Log it to see if it reaches Activity A. Upvote 0
What is PendingMessage? Is it serializable? Try passing a string, and Log it to see if it reaches Activity A.
LucaMs Expert Licensed User Longtime User Jul 27, 2014 #8 I remember (strange ) my first steps with B4A. I was searching for StartActivityForResult, for this topic; then, I spent days and I understood that what I have stated is the easiest and best. However, you can search on the site, there are probably many posts about this. I do not use them; maybe I can help you informing me better, but not right now, sorry. Upvote 0
I remember (strange ) my first steps with B4A. I was searching for StartActivityForResult, for this topic; then, I spent days and I understood that what I have stated is the easiest and best. However, you can search on the site, there are probably many posts about this. I do not use them; maybe I can help you informing me better, but not right now, sorry.
H Haris Hafeez Active Member Licensed User Longtime User Jul 27, 2014 #9 PendingMessage is a custom type declared as. Code: Copy Type PendingMessage (StrTo As String, StrMessage As String, Date As String, Time As String) This gets stored and retrieved using the KeyValueStore. [EDIT] Although there is a custome type in my program but I am not passing the custom type as extra to the intent. I am passing a String. Luca, seems I I have started off in your footsteps I will be happy if I can earn an Expert badge like yourself after a bit of hard work Upvote 0
PendingMessage is a custom type declared as. Code: Copy Type PendingMessage (StrTo As String, StrMessage As String, Date As String, Time As String) This gets stored and retrieved using the KeyValueStore. [EDIT] Although there is a custome type in my program but I am not passing the custom type as extra to the intent. I am passing a String. Luca, seems I I have started off in your footsteps I will be happy if I can earn an Expert badge like yourself after a bit of hard work
thedesolatesoul Expert Licensed User Longtime User Jul 27, 2014 #10 Did you try passing a string instead fo a custom type? Also do Log(intent.ExtrasToString) to see what you receive. Upvote 0
Did you try passing a string instead fo a custom type? Also do Log(intent.ExtrasToString) to see what you receive.
H Haris Hafeez Active Member Licensed User Longtime User Jul 27, 2014 #11 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) ? Upvote 0
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) ?
thedesolatesoul Expert Licensed User Longtime User Jul 27, 2014 #12 No, not any object. It needs to be serializable. For some reason I think the B4A Custom Type is not. You can try sending a List or a Map. Upvote 0
No, not any object. It needs to be serializable. For some reason I think the B4A Custom Type is not. You can try sending a List or a Map.