I'm working on an Android project in Java and I'd like to get the MotionEvent when the user hits the back button (onBackPressed).
I know how to override the back button press, and i know how to get the touch event from touches in my activity, but I couldn't find a way to get the touch event details out of the back button press.
The goal is to write the user's touch event details (as if the user touches a regular view) to a file, even when the back button is pressed.
Is it possible? if so, how can I do it?
Related
Through DispatchGesture, I need to somehow click on the back button, but do it programmatically, without clicking on the button or reproduce finish(), only in another app
I found a code that only clicks on the given coordinates
Thanks in advance:)
UPDATE
I found this: Trigger back-button functionality on button click in Android, but I want to make a click from Service
Suppose I move to another activity from my current one and then I need to go back to previous activity by pressing the back button originally present in the phone along with a home button and menu button. I have disabled my Action Bar and I don't want to enable it. Nor I want to create an icon in my activity that represents back.
Please Help!
to initiate the back operation you can call
super.onBackPressed();
from your activity.
I am working on a small app. When the user presses the app icon it starts activity A, which in turns starts activity B. Activity A then completes. B is set up as a main menu and can start other activities: the user can navigate back to B with the back button.
If the user navigates back to B and presses the back button the app moves into the background and the user is at their home screen. I have not overridden anything; this is the normal navigation.
At this point, if the user presses the app icon the app restarts. I understand that when the app is in the background the OS can close it for memory purposes, but this happens every time - regardless of how much memory. Is there a way to change this behavior? I already figured out how to stop this action with the home button with:
if (!isTaskRoot())
But I need to stop the action on the back button.
You can override onBackPressed() of Activity B like this,
#Override
public void onBackPressed () {
moveTaskToBack(true);
}
The app will be hidden when the user presses the back button, but it's state will remain the same. And when it is reopened, it will appear just as it was when you left it.
I have a button and a textview with the number 1 displayed when my app is running. When i press and hold the button i want the value to continuosly increment till I let go of the button. It is very frustrating for me because i used to know how to do this and it was as simple as setting the button properties to something in xml. However I have forgotten how and i have searched through the internet and the examples i have found implement an ontouch listener that only increments the value by one. But i want the value to be increment continuosly depending on how long the user presses the button. this is not a repeat of
Triggering event continuously when Button is pressed down in Android
Triggering event continuously when Button is pressed down in Android
as they did not work for me. so can some remind me how to get a button to increment a value continuosly when you press and hold the button?
Use onTouchListener and start/stop your counter routine on MotionEvent.ACTION_DOWN and MotionEvent.ACTION_UP
Android long-touch event
bramburys answer in the link above worked perfectly whilst other answers incremented one at a time when the button was pressed whilst bramburys incremented continuously.
I'm developing an android application and when I press the back button from my device (normal press time for a person, 1 second or less), it skips from my activity, to the previous activity (menu) and then exits the application.
But if I tap the back button quickly, it reacts as expected, it goes to the menu.
I've tried to find a solution but no success.
I've always tried to override the back button default behavior but no success either.
Is there a way to set a reaction time for the back button to react?
Many thanks in advance!
P.S.- I have other activities that maintains the expected behavior in back button when pressed with a normal press time.
"Is there a way to set a reaction time for the back button to react?"
Yes, you can simply record the time when the button is pressed and react differently in onBackPressed by calculating the (currentTime-lastTimePressed)
To allow this to work with previous activities, you can ask activities to startActivityForResult, so that when you finish your activity you can pass on the time as well to let them know if they should exit as well.
I was developing an extra option for an application that already exists, and I found out that I should extend not from the Activity from Android but an already extended Activity called SEActivity. So in this extended version of Activity they override the method onKeyDown like this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
else
return super.onKeyDown(keyCode, event);
}
By extending this SEActivity, the Back button works with the expected behavior.
Thanks anyway :)