Hi
I have two activitys and have following use case:
If user presses in the first activityOne the home button, onPause() is called. In onPause() I'd like to send an intent to the second activity to launch it.
Technically it works, but there is a huge delay betwend pressing the home button and launching the activity, about 4-6 seconds. If I send the intent by any other button pressed, it switches immediately.
Is it possible to speed up the switching or is this a given android behavior?
Regards,
cloooned
its a pretty bad level of coding to start an intent when onpause is called. consider just pressing the home button of your phone to exit the app leads you to some other activity instead.
also onpause will only be called when the activity goes to background. it will take a bit of time to reach that point.
Since the key event has been removed from the home button in Android 4.x, it seems to be one of the few chances to catch the home button pressed event. One other possibility is to overwrite the launcher with the activity and change the launcher default settings, but this would go to far.
Android prohibits you from starting an activity (from an intent) within 5 seconds after the user presses the home button. All startActivity intents will be delayed and executed after this 5 second interval. It is bad practice to start a new activity when the home button is pressed since the home button is the users last resort to escape an application.
Related
If any of you programming geniuses out there can figure out a way to add a small delay to the 4 EVO buttons a lot of folks would be very grateful.
Those buttons are just way to sensitive and are constantly getting bumped. They need a small delay (option?) to make them a little less subject to accidental triggering.
not a problem for me
i see what you mean, but honestly, i prefer them nice and fast and responsive with occasional accidents. my $0.02.
It wouldn't help I think because it's usually like part of your hand that sits over them.
yeah this is a terrible idea
I don't think it's a terrible idea... like 10-15 times a day if I am holding the phone with my right hand, in landscape mode, parts of my palm or whatever seem to activate home or search. PITA
Just to be clear, are you wanting there to be a delay in between button presses so that you don't accidentally hit the buttons multiple times when you meant to hit them once? Or do you want the buttons to require a long-press in order to activate them?
Saturn2K said:
Just to be clear, are you wanting there to be a delay in between button presses so that you don't accidentally hit the buttons multiple times when you meant to hit them once? Or do you want the buttons to require a long-press in order to activate them?
Click to expand...
Click to collapse
for me, I'd just like for the instant-press to be disabled, and make a half-long-press, of sorts. Basically, to disable accidental 'brushes,' that could activate the buttons. It's not a huge problem honestly, but it sure does make me miss having REAL buttons. I've never been a fan of capacitive buttons, like on my laptop. A real, old-fashioned button always works better.
This happens to me all the time too. I don't know if a half-long-press, short-press, or press-hold would really make any difference. I think I trigger the buttons in just about each of those ways accidentally daily. What I could see as a potential solution is a button lock app.. maybe gesture based and floats on top of any full screen apps? If only I was more cody, I would try my hand at making it..
Find the value or command that equals a long press and I can probably do it.
BuglessPete said:
Find the value or command that equals a long press and I can probably do it.
Click to expand...
Click to collapse
This is for 2.0, and it applies to hardware buttons. I'm not sure how the EVO deals with the buttons since they are capacitive touch buttons. And it may be different in 2.1 (and HTC for that matter). But it's a start:
From http://developer.motorola.com/docstools/library/Basics_of_Event_Management/
"Long Press Events
Prior to Android 2.0, detecting the long press was only available to UI elements by implementing the event listener OnLongClickListenerand registering the View with setOnLongClick(). In 2.0, support was added for a new event handler to detect long presses on hardware buttons.
Code:
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CALL) {
// A long press of the call key.
// Do our work, returning true to consume it. By
// returning true, the framework knows an action has
// been performed on the long press, so will set the
// canceled flag for the following up event.
return true;
}
return super.onKeyLongPress(keyCode, event);
}
The callback is triggered by any key press-and-hold. To determine what key was pressed you need to test for a specific key code."
I believe these are all of the key codes that would be returned: http://developer.android.com/reference/android/view/KeyEvent.html
Of interest:
Code:
public static final int KEYCODE_HOME
Since: API Level 1
Constant Value: 3 (0x00000003)
Code:
public static final int KEYCODE_SEARCH
Since: API Level 1
Constant Value: 84 (0x00000054)
Code:
public static final int KEYCODE_MENU
Since: API Level 1
Constant Value: 82 (0x00000052)
Code:
public static final int KEYCODE_BACK
Since: API Level 1
Constant Value: 4 (0x00000004)
thread moved to EVO General discussion
I too would really love to see some kind of hack that allowed for customizing the delays for these buttons. Even a 1 second delay option would be great. I accidentally brush those buttons several times a day.
Hey there,
I have a activity that i wish to be opened & closed as fast as possible. When i press the backbutton and then reopen the activity it opens instantly(what i want). BUT when i press the home button and they try and re open the activity it lags for 2-3 seconds. Even tho in my onPause im calling the onBackPresed() function...
any ideas how to fix this?
You could try putting "finish();" in the onPause() method, instead of calling the back button handler
Since upgrading to a stock Jelly Bean firmware, I noticed that pressing the home button causes a short 1 second delay before it actually does anything. It's enough to be annoying since it slows down returning to the home screen or moving to the default home screen.
The reason for the delay appears to be that it's waiting to see if you're going to make it a double-click. A double click launches the dreaded Vlingo voice control app or Google search dial by voice.
You can remove the delay by installing Advanced Home Button from the play store, and following the "Galaxy S2 hack" instructions within that app.
Now, pressing home instantly takes you to the home screen without the one-second delay.
The downside to this solution is that you lose the double-click functionality on the home button, but most people probably see that as a benefit anyway.
I am not the author of that app, nor do I know how it works or how to reverse it.
Or you can delete both and no more 1sec delay
I made a video so you can understand it better
So ... as you can see pressing the back button close the application or something like that and pressing the home button to leave it will result in a smooth animation when re-entering it
is there a way so i can change that ? i really like the way how application open when i leave them with the home button
I can't watch the video right now, but I will assume you are not talking about long-pressing the back button.
I guess that is just how applications work. Home button let's them run in the background and back button closes them.
The only way you can change it is with xposed or a custom rom.
Edit: Changin the behavior will also take away the ability to use it for what it was intended: to go back.
You can assing it another function or disable it altogether, but either way, you will lose the back function of the button and will have to use the app integrated back buttons.
prologikus said:
I made a video so you can understand it better
So ... as you can see pressing the back button close the application or something like that and pressing the home button to leave it will result in a smooth animation when re-entering it
is there a way so i can change that ? i really like the way how application open when i leave them with the home button
Click to expand...
Click to collapse
From another source:
Back Key :
If you press Back Key, onPause(), onStop() and onDestroy() callbacks will called.
Activity will created again by system calls onCreate() callback, then onStart() and onResume() callbacks will be followed.
Home Key :
If you press Home Key, onPause() and onStop() callbacks will called.
Here Activity will restart by system calls onRestart() callback, then onStart() and onResume() callbacks will be followed.
Click to expand...
Click to collapse
The back key will quit the application while the home key will let it run. That are the main differences. That's why they act differently. If you still want it, I know that CM based roms support changing of the layout.
but how ? or how i can search ... i only found that some layout are in generic.kl but here is just a simple match up, keys with functions idk ..
OR this is writed in the app code ?
Hi,
I would like to be able to detect if my Activity has been obscured by, say, a system alert or some other overlay (for example the power menu when I long press on the power button, or the volume control Toast), or some malware that detects the launch of my Activity. I noticed that the foreground app in this case would still be my app, so I can't simply base it on what the foreground app is. I also notice that onPause() isn't called when my Activity is obscured, so I can't put any logic in onPause() either. Even if I can though, I would then have to differentiate between a system alert/overlay and the user pressing the back/home button.
Are there any other ways for me to accomplish this?
I am able to partially accomplish this by placing OnTouchListener to my UI elements as well as the root View. In this case, if the overlay relays touch events to my activity, AND the part of my Activity that was touched is obscured, then I'm able to detect that it's obscured and do something about it. However, it still doesn't guard against 2 cases:
1. If the overlay doesn't relay touch events to my Activity. In this case the OnTouchListener won't be called.
2. If the area that was touched is not obscured by the overlay, in the case of a partial overlay. In this case, the OnTouchListener won't know that the Activity is partially obscured, it only knows that it's not. This still leaves me open to a peephole attack.
I'm not convinced that there is a way. I know one can detect that the app is paused or exited, but not that it's obscured.