how to execute application in background

by Honest » Mon, 26 Jan 2009 20:53:45 GMT


Sponsored Links
 HI,

How can i execute my application in background and how can i start
application when phone starts ?

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



Other Threads

1. Class derived from IntentService must have default constructor

I'm posting this to share the lessons I learned while working with
IntentService.

IntentService has a single constructor that takes a string argument
"name". The documentation has no description of what name is used for.
In looking at the sources, I found that its only use is in naming the
worker thread for the IntentService. This thread is named IntentService
[name].

I initially implemented the constructor of the derived class to also
take a String argument and passed it along to the derived class. This
is wrong. This will cause the startService() call to generated a
java.lang.InstantiationException in the application containing the
service i.e. you don't get the exception in the application calling
startService(). A clue to the actual problem is a little further up in
the logs:"newInstance failed: no <init>()"

The derived class must have a Default constructor and that constructor
must call super() passing a string for the name component of the
worker thread name.

public class MyIntentService extends IntentService
{
    public MyIntentService() {
        super("MyIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent)
    {
        // Handle events on worker thread here
    }
}



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

2. Application gets killed due to a timeout

Hi,

since Cupcake our application became very unstable. It often dies and
users have to restart it manually. The log shows that it was killed
due to a timeout, something like this:

<code>
W/ActivityManager(   56): Timeout of broadcast BroadcastRecord
{434824c8 android.provider.Telephony.SMS_RECEIVED} -
receiver=android.os.binderpr...@434ba458
W/ActivityManager(   56): Receiver during timeout: ResolveInfo
{434663b8 com.websafety.android.client.SMSReceiver p=0 o=0 m=0x108000}
I/Process (   56): Sending signal. PID: 4702 SIG: 9
I/ActivityManager(   56): Process com.websafety.android.client (pid
4702) has died.
</code>

Previously it was working all fine. It also works fine on Emulator.
But it is extremely slow on HTC Magic. We found that sometimes it does
take some time to respond to some requests (such as the broadcast
above for Telephony.SMS_RECEIVED), while in other cases (for example,
we have a background Service which starts on BOOT_COMPLETED) it seems
the problem is not in our code. Previously, it was taking only 5
second for the service to start, while now it takes 15 seconds - the
same application, on the new Cupcake phone. I tried converting the
service onStart into a simple "new Thread().start()" - and guess what,
that gets killed as well before it reaches my first line of code. For
the cases when our code is "slow" it became much slower with Cupcake
(or is it HTC Magic?).

I guess I have two questions to Google, but if someone has workarounds
or similar experience please speak up:

1. Why is Cupcake so slow?
2. Can you document the expected time limits within which some
methods, either event listeners or overridden, should return before
they are considered timed out? We don't mind updating the application
by making sure we do respect those limits, but not knowing them costs
us too much money as we are discovering them through customer support
calls. The example methods which I suspect do have those limits are
Service.onStart, ContentObserver.onChange to name a few.

Thanks.

Denis
--~--~---------~--~----~------------~-------~--~----~

3. ListView inside LinearLayout inside ScrollView

4. things turning on in the night

5. why MotionEvent.ACTION_DOWN doesn't fire in onTouchEvent?

6. **never ever** use Toasts with Activity context

7. Android Maket Place Apps