StartActivity intent fails when certain apps are running
I am running into a critical conflict of sorts. My app is a remote service which essentially starts an activity when the screen goes to sleep. How it does this is very simple via screen off broadcast receiver and then an explicit intent to start the activity as a new task. The activity is basically in charge of responding to key events and displaying some simple text.
Thanks to a few window flags added in 2.0, activities can do this. They can be created in a way that either puts them on top of the lockscreen, or completely dismiss the lockscreen. This way they basically have focus without the lockscreen having to be dismissed by user. The alarm clock in 2.0 uses the flags to wake up the device and show the alarm dialog. I use them to place my activity when the screen sleeps so the user sees a custom wakeup lockscreen. The reason we create it at screen off is to get rid of lag the user experiences at wakeup involving first seeing the lockscreen, then seeing the activity appear. Also doing it immediately at sleep allows it to have focus so it can handle key events effectively.
The process works perfectly except in certain apps. So far, it seems the bug is consistent while browser (and even dolphin browser) as well as the facebook app are running. The bug never happens in GTalk or Launcher. It is rare but can still be duplicated in the messaging app every so often. I can't figure out why my activity doesn't get created at sleep while these apps are active. My remote service still gets the screen off broadcast and does the startActivity for the explicit intent, and that's all I get in the log. My onCreate is not being called. Instead it gets called when we wake the screen up again.
I have tried, as a control, to hold the partial wakelock starting when my remote service gets created, and the issue persists. So I don't believe it is a problem that the CPU has gone to sleep. Since only these particular apps cause the issue to duplicate, I can't imagine why the activity start fails. What could those apps be doing to interfere with another app's ability to get created? I use singleInstance as the launch mode so that I can ensure that the activity will never be able to be recalled by user process. I want it to go away when user unlocks and it is working fine like this, as long as it is able to be created. The singleInstance ensures I can have the same lockscreen handle an intent to do something specific based on user actions that the remote service monitors.
my source code can be viewed on my project page. http://code.google.com/p/mylockforandroid/source/browse/#svn/trunk/myLock/src/i4nc4mp/myLock
the issue happens to both my CustomLockService and NoLockService variations. These two services will start Lockscreen or ShowWhenLockedActivity and the bug is witnessed. The build illustrating the bug's end result-- user has to try to unlock 3 times due to the bug because on wakeup when the oncreate finally succeeds, user is seeing the activity when normally it would have auto-dismissed thanks to key event logic that also isn't seeming to happen due to the delayed onCreate, so they have to send it to sleep again. Now that the activity is properly done being started, and screen is asleep, the expected functionality happens at next wakeup-- can be downloaded also from the downloads tab.
This seems like an extremely irrational thing to be caused only by specific apps. I am quite baffled and out of ideas for a solution unless I've made some critical mistake in my activity definitions.
Asked by: Alissa253 | Posted: 25-01-2022
Answer 1
The answer is actually a bug in android that has been in review for a while. It has to do with the home key. For some reason start activity calls as new tasks are getting stopped after the home key has recently been launched. I never noticed the connection during the testing of this. The bug was not consistent and the factor of consistency was whether home button had been used during the wake in question
Here is the bug report: http://code.google.com/p/android/issues/detail?id=4536
Answered by: David712 | Posted: 26-02-2022Similar questions
android startactivity
I have an application that contains 3 activities A, B and C. The activity A is the one that gets started when I start my app. From A I start B using mIntent.setClass(A.this, B.class);, then startActivity(mIntent); this goes well. What goes wrong is when I want to start the activity C from B.
this how the manifestfile looks like:
<activity android:name=".B"/>
&...
android - How does startActivity decide whether to start a stopped activity or create a new one?
Long story short, I have a LaunchActivity which is always called by LAUNCHER (i.e. the home screen). It then starts LoginActivity and then closes itself.
This is the flow:
User launches app
LaunchActivity starts, starts
LoginActivity and then calls
finish() on itself (At this point
LoginActivity is the only Activity
on the stack)
User press "Home" button, stopping
LoginActivity...
java - Is it possible to start an activity in a different apk using startActivity on Android using the activity name or similar?
I have tried to write an Android application with an activity that should be launched from a different application. It is not a content provider, just an app with a gui that should not be listed among the installed applications. I have tried the code examples here and it seems to be quite easy to launch existing providers and so...
android startactivity
I have an application that contains 3 activities A, B and C. The activity A is the one that gets started when I start my app. From A I start B using mIntent.setClass(A.this, B.class);, then startActivity(mIntent); this goes well. What goes wrong is when I want to start the activity C from B.
this how the manifestfile looks like:
<activity android:name=".B"/>
&...
android - Why should I use startActivity in a Service
Why should I use startActivity() in a Service? If I need an Activity a have to call an activity and if I need a "delayed activity" I have to use the notification. So, why should I use startActivity()?
startActivity on Android
so i've been trying to get my application to run an Activity via an intent and it works fine, when i then assign the finish(); method, it returns to the activity that called it. The only thing i don't understand is that i'm not sure if the callee Activity is put onPause while the called Activity is in-front. I've tried to setup a toast message in the onPause() method of the callee Acitivty but it ...
android - startActivity crashes when trying to respond to menu click
I know this has been covered elsewhere, but I'm new to the Android platform and am having a hard time figuring out how to add basic menu options to my first app.
I have an options menu setup using
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
and
<?xml ...
android - Why does startActivity work in one method and fail in another?
I am an android beginner.
I'm struggling to understand why startActivity runs properly when copied from a tutorial I found and fails when I make the smallest change.
Code from the tutorial:
private class ButtonHandler implements View.OnClickListener {
public void onClick(View v) {
handleButtonClick();
}
}
private void handleButtonClick() {
startActivit...
android - Calling the function "startActivity" in other class and file doesn't work
I want call the function startActivity in two ways:
First (It works):
public class HelloWorld extends Activity
{
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == 1){
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:660718109")));
}
else {
return super.onOptionsIt...
android - startActivity with an implicit category-less intent
It seems to me that if startActivity is called with an implicit categoryless intent, only activities with an intent filter specifying the default category (android.intent.category.DEFAULT) can be launched.
The category is not needed in the intent filter for services if we use startService instead of startActivity.
Does everybody see the same behavior ?
Is it documented somewhere in the Android offi...
android - startActivity doesn't work from a Fragment in HoneyComb
The onCreate() method is called but the new Activity never appears. No errors are logged.
Follow up - There was no problem with calling startActivty() from a Fragment (we had a bug in the second Activity that caused it to exit immediately).
startActivity() from a Fragment works exactly like startActivty() from outside a Fragment.
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android