I use a service to launch applications by gestures. That works fine. But when I press the homebutton (doesn't matter when and where) then the launch of the app (right after pressing the homebutton) from the service takes about 2-3 seconds. It is also possible to launch the app 2-3 seconds after pressing the homebutton, then the app starts immediately. Another way is to open a random app before launching an app from the service. Then there also is no delay.
To summarize:
After pressing the homebutton at anytime, a launch of an app from the service (right after pressing the homebutton) with the code below, needs about 2-3 seconds. Launching the app 2-3 seconds after pressing the homebutton launches the app immediately.
startActivity(getPackageManager().getLaunchIntentForPackage(item));
Toast.makeText(getApplicationContext(), "TestTest", Toast.LENGTH_SHORT).show(); //just for testing
The Toast-Message (right after the startActivity-Command) always shows up immediately, so the service is working all the time, even right after pressing the hombutton.
That problem is really strange. How can the homebutten "block" the startActivity-Command in the service for a few seconds?
Any ideas? Thx