Running a program when emulator start

by Jaikishan » Wed, 18 Jun 2008 23:26:39 GMT


Sponsored Links
 Hi,

I was wondering if its possible to start a program automatically in
the background as soon as the emulator gets started? The idea is to
show some message on the status bar.

Thanks
-J

--~--~---------~--~----~------------~-------~--~----~



Running a program when emulator start

by Damien » Wed, 18 Jun 2008 23:51:32 GMT


 Android broadcasts a message on boot. See

 http://code.google.com/android/reference/android/content/Intent.html #BOOT_COMPLETED_ACTION

If you have something listening for this broadcast then it will start
as soon as the
boot has completed.

Regards
D.



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Running a program when emulator start

by Jaikishan Jalan » Thu, 19 Jun 2008 04:01:01 GMT


 Hi,

Thanks for the reply. I understood what you are saying. I wrote my Intent
Receiver which will receive to this broadcast message. Now I want to run a
background process which keeps running forever ( which do some update after
every sometime t). My approach to this problem is this : I am going to write
a Service Calls and call it from the onReceiveIntent method of the
IntentReceiver I wrote. Now, onStart method of the Service Class, I will
create a thread that updates and then sleep for time t and keep running.

Is this a recommended way to approach this problem?

Thanks
J

-----Original Message-----
From: android-developers@googlegroups.com
[EMAIL PROTECTED] On Behalf Of Damien
Sent: Wednesday, June 18, 2008 8:51 AM
To: Android Developers
Subject: [android-developers] Re: Running a program when emulator start


Android broadcasts a message on boot. See

 http://code.google.com/android/reference/android/content/Intent.html #BOOT_CO
MPLETED_ACTION

If you have something listening for this broadcast then it will start
as soon as the
boot has completed.

Regards
D.






--~--~---------~--~----~------------~-------~--~----~



Running a program when emulator start

by Zach Hobbs » Thu, 19 Jun 2008 10:40:05 GMT


 If you are doing periodic updates I would think about using the AlarmManager 
to kick off the process after specified intervals.  If you create a service 
it's possible that it will be killed by the OS to free resources.

 http://code.google.com/android/reference/android/app/AlarmManager.html 

-- 

Zach Hobbs
HelloAndroid.com
Android OS news, tutorials, downloads 








--~--~---------~--~----~------------~-------~--~----~



Running a program when emulator start

by Jaikishan Jalan » Thu, 19 Jun 2008 14:00:57 GMT


 i Zach,

So, Once I receive the BOOT_COMPLETED_ACTION Intent, what is the problem if
I start a thread which keeps running and sleep for time "t" and then again
start running. Is this a bad approach ? Here is my code :

This code will do some HTTP Post Request every 5 second. The idea is to run
this in the background once my the emulator is started and keep this running
until the mobile is switched off.

import android.content.Context;
import android.content.Intent;
import android.content.IntentReceiver;

public class AddressLogService extends IntentReceiver{
@Override
public void onReceiveIntent(Context context, Intent intent) {

Thread tr = new Thread(null,AddressTask,"Address Logger");
tr.start();
}

private Runnable AddressTask = new Runnable() {

public void run(){
while(true){

try{
//I do some HTTP Post Request.
Thread.sleep(5*1000);
}catch(Exception e){}
}

}

};
}

Thanks
-J


On Thu, Jun 19, 2008 at 8:09 AM, Zach Hobbs <[EMAIL PROTECTED]> wrote:


<http://www.geocities.com/jai_ism>

--~--~---------~--~----~------------~-------~--~----~



Running a program when emulator start

by hackbod » Thu, 19 Jun 2008 16:12:37 GMT


 f you keep yourself running in the background forever, you are taking
those resources from the rest of the system forever. This is not a
polite thing to do. By using the alarm manager, the system has more
freedom to kill your process when it is not needed.

A service that keeps itself running forever but not actually doing
anything most of that time is a big waste of valuable resources, so
something to avoid.

And doing an HTTP operation every 5 seconds is WAY too much. Keep in
mind, every line of code you run is lowering the level of the battery,
every network operation you do is lowering it even more. Doing this
kind of thing every 5 minutes is the minimum scale you should be
thinking about.

On Jun 18, 11:00pm, "Jaikishan Jalan" <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Running a program when emulator start

by Jaikishan Jalan » Thu, 19 Jun 2008 16:22:57 GMT


  completely understand that making an HTTP request every 5 seconds is not
the best way to keep the user happy :). I am just trying to prototype it to
see it working. Ideally, in production the application has to make an http
request once every hour or so. Also, I don't want that even my background
process is sleeping, I don't want to get it killed. It should be killed only
when the user turns off its mobile.

So one application, is when the mobile is started, I will start a background
process. This background process will pull a new quote from a server once
every hour and display it to user. ( Assume for the time being that all the
android mobile user will want this capability [Which I know is not true]).

Do you still I should use AlertManager or run my own thread? One more
related question I had is there any way to measure how much battery power my
background process will overall take ?

Thanks
-J

On Thu, Jun 19, 2008 at 1:42 PM, hackbod <[EMAIL PROTECTED]> wrote:


--~--~---------~--~----~------------~-------~--~----~



Running a program when emulator start

by zero » Thu, 19 Jun 2008 22:12:17 GMT


 ay i suggest another option?
get yoursefl a copy of the latest openintents build,
write a Service class that does whatever you want,
then on some point in your app just call
org.openintents.provider.Alert.registerManagedService(myServiceClassName,myTimeIntervall,useWhileRoaming)
;
and you should be good to go :)


On Jun 19, 10:22 am, "Jaikishan Jalan" <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. *** Dev Tools - Terminal Emulator - sdcard ***

Through Android Emulator, I am trying to create a folder using dev
tools > Terminal Emulator.

The terminal emulator gets launched with the SHELL PROMPT.

(1)
However, when I try to type a command, at the bottom of the screen,
some suggestions are shown - but in CHINESE CHARACTERS. Dont know why
CHINESE?

(2)
Also, the characters I type are not being displayed properly. For
example, typing "cd" (for change directory), shows "^P".

I need to go to the sdcard folder using "cd sdcard" and create a
directory using "mkdir" and then copy some files into it.

Please let me know if I am going wrong somewhere?

Also, is there any other way of creating a directory inside "sdcard"
folder?

Thanks for your suggestions.

-- 

2. Simulate the SIM in the emulator how to do that?

For calling and sending sms, you can use the eclipse to simulate these
on the emulator. What else do you need?

Open the "Emulator Options" from the Android views.

Thanks and Regards,
Kumar Bibek.



> 

3. How to run a class in background among a package of class

4. Android square root function

5. Invoke GlobalActions dialog (Shutdown/Reboot...) on Android-x86

6. Simulate the SIM in the emulator how to do that?

7. How many Android phones have touchscreens?