Android Tutorial Starter Service - Consistent & Single Entry Point

Status
Not open for further replies.

PSEAD

Member
Licensed User
I meant to ask if it would be good practice to kill it when exiting an app completely to stop the service using resources unnecessarily?
i.e. to free up memory without having to rely on android to do so.
You don't recommend killing the starter service -- would this apply even when it is no longer needed?
 

lemonisdead

Well-Known Member
Licensed User
You don't recommend killing the starter service -- would this apply even when it is no longer needed?
Hello,
I guess Erel was thinking about stopping the Starter service when the activity was put on pause. But, as told you previously it is a service only and you have to decide if you want to stop it when you don't need it anymore.
The decision is yours :
  • if you don't stop it, when you restart the app the service restarts. This means that if it was not killed previously you can retrieve previously stored values in Process_Globals variables
  • if you stop it, you restart with brand new Process_Globals
 

PSEAD

Member
Licensed User
That is a good point. An end user's first reaction when encountering a problem could be to close and restart the app, assuming that this would reset all variables. Without specifically terminating the starter service, closing and opening an application would not reset anything, possibly causing some confusion.
I guess it would depend on the application, but certainly something to be aware off. I have tested this effect using the "programflow" example and it does exactly as expected.
 

ivan.tellez

Active Member
Licensed User
It's somenting weird with android.

I have an App with 5 activities, If the app is not on the main activity and the user presses the home button, the app will send to background, after some time is killed (partial)

As Erel said;
the OS can start the process from a different activity
So the process was killed, but when the app is launched, android insist on launch another Activity (instead of Main)

Starter service resolves this partially, now, starter is allways the entry point and can initialize and launch Main Activity. BUT when the activity that was originaly intended to launch by android, has some objects initialized o_O

So, Is there a proper way to know in the starter service if an activity is initialized and kill it?

Thanks
 

ilan

Expert
Licensed User
The starter service should be excluded from compiled libraries. Its #ExcludeFromLibrary attribute is set to True by default
i have not understood this sentence, can someone explain to me what it says? (in simple english please :D)
 

klaus

Expert
Licensed User
You can compile modules to a library.
By default all modules are included exept the Main module which is automatically excluded from the library the Starter service is also excluded by default, because on top you have #ExcludeFromLibrary: True.
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True

#End Region


Lets' take an example:
You have the Main module, two Class modules and one Code module.
The Code module is only for testing.
Now you want to compile both Classes into a library but without the Code module.
For that you must add #ExcludeFromLibrary: True on top of the Code module.
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True

#End Region
#ExcludeFromLibrary : True
 

ilan

Expert
Licensed User
Thanx klaus. I didnot knew that i can compile a module to a library.

So that means i can create a code module and then create from it a lib to use it in all my apps instead of copying that module?

So it is possible to create libs without knowing java??
 
Last edited:

DonManfred

Expert
Licensed User
So it is possible to create libs without knowing java?
As they are based on B4A Source, yes.

You can have a look at my Dropbox Class.
DropboxV2_libraryfiles_v093.zip is the Class compiled to a Library
The Class is inside DropboxHTTPv2librarysource_V0.93.zip

Try to open the project inside.
You see a blank main module but note the additional commands in Region Project attributes
B4X:
    #LibraryVersion: 0.93
    #LibraryAuthor: DonManfred <msy1912@gmail.com>
    #LibraryName: DropboxHttpAPI
a blank starter and the dropboxclass itself...

Use Compile to Library on this project
It will - based on #LibraryName: DropboxHttpAPI - create a DropboxHttpAPI.jar and a DropboxHttpAPI.xml inside your additional libraries folder.

The result is that from now you can use the library DropboxHttpAPI to use the Dropboxclass. No need to add the Class-module to your project.
 
Last edited:

klaus

Expert
Licensed User
Have a look at chapter 12 Class modules and more specific 12.6 Compile a class into a library in the B4A User's Guide.
There is a concrete example included with source code.
 

ilan

Expert
Licensed User
Have a look at chapter 12 Class modules and more specific 12.6 Compile a class into a library in the B4A User's Guide.
There is a concrete example included with source code.
Thank you klaus :)
 

ValDog

Active Member
Licensed User
Based on what I've read in this thread am I correct in assuming that "Starter:Service_Create" is only called one time - upon application startup. So instead of using "If FirstTime" calls in my "Main:Activity_Create" I could instead place those items in "Starter:Service_Create?"
 

luke2012

Well-Known Member
Licensed User
If I execute an Activity.Finish statment within the Main module the Stater still running?
 

luke2012

Well-Known Member
Licensed User
Yes. It will be running until Android kills the process.

You can call StopService (Starter) if you like to manually stop it.
Thanks for the reply @Erel. In my case this is perfect because I need that the starter still running :)
 

bgsoft

Well-Known Member
Licensed User
Hi

This code does not work when the device is restarted (main does not run):
B4X:
'  Starter Service
#Region  Service Attributes
   #StartAtBoot: true
   #ExcludeFromLibrary: True
#End Region


Sub Service_Create
   StartActivity(Main) 
End Sub
This is the Log:
** Service (starter) Create **
** Service (starter) Start **
** Service (starter) Start **

This same code in a "normal" service module, if running Main

Why? :D the starter Service behaves different service modules ?. I have looked at the forum and I have not seen any explanation

Note: If I run the application from the desktop runs well.

This is the Log:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **


regards
 
Status
Not open for further replies.
Top