tags:

views:

131

answers:

2

Hello,

I am new to Android, and I need some advices for start up.
I want to build an application, which will show up, when the user gets into some hot situation.

By hot situation I mean:

  • the GPS/cell coordinates are in known zone;
  • known Bluetooth device detected;
  • known Wi-Fi network detected;
  • weather info has change;

I see something running in background and when one of the clauses hit, it will trigger and open the app.

  • How to get started?
  • How do I make sure my app won't be shut down?

As I read somewhere that Android OS will terminate apps if memory out occurs or consumes too much, and my app would consume a lot, making repeated measures/checks to see if situation changed.

Regards,
Pentium10

+1  A: 

You need to use a Service for the part of your application that runs in the background.

You might find the Application Fundamentals document in the Android Developer Documentation helpful. It says this about Services:

A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it.

In you case you might find the LocationManager Service helpful. It is a system Service which will you can use to notify your application based on GPS position.

However, I think you'll have to write your own Services to monitor Wi-fi, Bluetooth and weather.

You can use the AlarmManager Service to get your Service to perform particular tasks at certain intervals.

Dave Webb
Will the service be subject to termination by the OS if uses too much resources?
Pentium10
what do you think, will the enumerated task drain the battery a lot?
Pentium10
The Service can be closed if the phone doesn't have enough resources to meet all foreground requirements. It's all covered in the *Application Fundamentals* document I linked to. I highly recommend you read it from beginning to end; I did so and found it invaluable. It's hard to say what the battery drain of your Service would be. A sensible Poll Interval would help. The Locale application -http://www.twofortyfouram.com/ - does very similar things to your suggested application and doesn't seem to drain my battery too much.
Dave Webb
sorry, I'm a beginner and can't locate yet the precise information I'm after. Do you think it's best to create multiple services for the different tasks?
Pentium10
Hard to say, but probably best to have a single Service so you only have the overhead of a single Dalvik VM.
Dave Webb
do you know the Locale app you mentioned as a coder? I am wondering if I would be able to get some results from it, and this way I can do my app as a plugin for Locale. What do you think?
Pentium10
All I use Locale for is putting my phone on Silent automatically when I get to work. No idea what you can do with the plug-ins.
Dave Webb
A: 
Valentin