I 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:

>
> If 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:00 pm, "Jaikishan Jalan" <[EMAIL PROTECTED]> wrote:
> > Hi 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:
> >
> > > 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
> >
> > > On Wednesday 18 June 2008 16:00:38 Jaikishan Jalan wrote:
> > > > 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: [email protected]
> > > > [mailto:[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#.
> ..
> > > >O MPLETED_ACTION
> >
> > > > If you have something listening for this broadcast then it will start
> > > > as soon as the
> > > > boot has completed.
> >
> > > > Regards
> > > > D.
> >
> > > > On Jun 18, 11:18 am, Jaikishan <[EMAIL PROTECTED]> wrote:
> > > > > 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
> >
> > <http://www.geocities.com/jai_ism>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to