callsubdelayed3 order of subs executed

Eduard

Active Member
Licensed User
Longtime User
I'm starting an activity with callsubdelayed3. But the order that sub's are executed is not what I would want/expect.

B4X:
CallSubDelayed3(A_show,"Activity_Start1",emailaddress,g_id)

first 'activity_create' is executed, than 'activity_resume' and after that "Activity_Start1" (the sub that I passed as and parameter to callsubdelayed3)

I need to display data based on the parameters emailaddress and g_id. Since this data needs to be displayed again if user had left the app, this is done in activity_resume.

I could display the data twice: both in Activity_start1 and in activity_resume, but that's twice as slow. Is there a way to call a sub only once after both activity_start1 and activity_resume?
 

melamoud

Active Member
Licensed User
Longtime User
You can start the activity with startActivity and pass an intent as parameter
In the resume you can call activity.getStartingIntent and you can get the params you wanted to pass.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
CallSubDelayed first starts the activity if it not the visible activity. The result is that Activity_Create and Activity_Resume are first executed.

I could display the data twice: both in Activity_start1 and in activity_resume, but that's twice as slow.
I prefer to start with the simplest solution. Is this really slow? Can you post the code that "displays the data"/
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Is this sub getting called also in the activity_resume? If so, why not simply calling a startactivity, including emailaddress and g_id as process globals?
 
Upvote 0

Eduard

Active Member
Licensed User
Longtime User
CallSubDelayed first starts the activity if it not the visible activity. The result is that Activity_Create and Activity_Resume are first executed.

I prefer to start with the simplest solution. Is this really slow? Can you post the code that "displays the data"/

Depends on the amount of data. It's a database with photos and descriptions and it could be >1000 records. I'm using a scrollview with for each record a panel, imageview and a couple of lables. I'm already looking at multithreading to load the list in the background so the app doesn't freeze while loading. I also considering to load blank panels and fill them only when the user is scrolling to them.

First I had the entire list defined as a global, but Android seems to really like to clean it up in order to free up memory even if they are process globals. Later I decided it is to big a list to use as globals, so I'm loading it upon startup of the activities that use it.

You can start the activity with startActivity and pass an intent as parameter
In the resume you can call activity.getStartingIntent and you can get the params you wanted to pass.
How can I do that? Sounds like a possible solution

Is this sub getting called also in the activity_resume? If so, why not simply calling a startactivity, including emailaddress and g_id as process globals?
I try not to use process globals to communicate between activities if possible. But yes, that is an option.
 
Last edited:
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
using intent to start an activity

to use startActivity with an intent use this code i your other activity or service: (assuming main is the target activity)
B4X:
      If IsPaused(Main) Then       ' startonly if closed alreday
         Dim Intent1 As Intent
         Intent1.Initialize("", "")
         Intent1.SetComponent("<put here your full app package name x.y/.main")
         Intent1.PutExtra("emailaddress", "[email protected]")
         StartActivity(Intent1)
      End If
you can put as many extra param as you want

in your resume method in the target activity do this code:
B4X:
Dim intent1 As Intent : intent1 = Activity.GetStartingIntent
If (intent1.HasExtra("emailaddress") = True) Then ' running from your service not user justrun this (if possible) 
 ' use intent1.GetExtra("emailaddress") to get the email address you sent.
End If

I hope this help
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Depends on the amount of data. It's a database with photos and descriptions and it could be >1000 records.
I try not to use process globals to communicate between activities if possible. But yes, that is an option.

1000 records of photos? I would strongly recommend a partial load using efficient coding.


Why not using process_global in that case? You define it in your other activity or module, then let the other activity check for each value. It cannot happen that the variable loses its content in that small amount of time, if that's you worry about.
 
Upvote 0

Eduard

Active Member
Licensed User
Longtime User
to use startActivity with an intent use this code i your other activity or service: (assuming main is the target activity)
I hope this help

Thanks. I believe I need to change the manifest as well? I did the following
B4X:
Intent1.SetComponent("my.package.name.ActivityName")

and got the following error:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act= flg=0x20000 (has extras) }

I tried to add an intent-filter with help of Manifest Editor - Basic4android Wiki
but with no success.

1000 records of photos? I would strongly recommend a partial load using efficient coding.


Why not using process_global in that case? You define it in your other activity or module, then let the other activity check for each value. It cannot happen that the variable loses its content in that small amount of time, if that's you worry about.

The photos (thumbs) wil be only loaded when necessary based on the scroll view position. I also think a partial load would be better. But it makes It even more complicated. I haven't decided yet.

I agree a process_global is probably the easiest way
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
No need to touch the manifest
And you component line is wrong
See my example you are missing the /. Between your app name and the activity name
 
Upvote 0

Eduard

Active Member
Licensed User
Longtime User
No need to touch the manifest
And you component line is wrong
See my example you are missing the /. Between your app name and the activity name


Thanks. I tried that too earlier. It seems the activity name must be lowercase:


B4X:
Intent1.SetComponent("my.package.name/.activityname")

I'll use this for now. I'm probably going to use intents more. So it's good to start getting used to it.
 
Upvote 0
Top