How to press the back button programmatically in android - android

I want to know how to press the back button when a button is clicked in a service in android.
I want to make a program like assistive touch assistant in samsung phones..
Please help me!

First of all, there are no back buttons in a service. A service does not have a UI. If you mean an activity, just call finish().

Related

Opening Activity from anywhere using buttons

I am working on an App that should perform a function when a certain sequence of buttons are pressed from anywhere in an Android device. For example, if the volume down button is hold pressed for more than 10 seconds and activity in the app will start.
I have been looking up stuff, and all I seem to get is how you can listen to the button press whilst the App is open. Kindly, help on how I can do this with the App closed, or at least in background.

Detect key home press from service

Hi i have broadcast application and I have a floating window
purpose: to view this window every activity I visit.
so my goal is that to minimize my floating window when I user press home button
SO my question is is there any way to detect if home is press?
if yes please guide me into it.
thanks in advance.
Pss.. I also tried to search it on this website but seems I haven't found a solution yet on it.
Note: it should be on service not in activity

how to continue running an android app even when back button is pressed

I have made an android app that runs successfully. But when back button is pressed it stops. My app is supposed to work even when back button is pressed.
How to do this?
and where to place this piece of code?
You should implement a router in your app. See ampersand-router for example. It will handle the "back" events of the browser.

Android - Application closes on pressing power button

I have made an application named TicTacToe having AI. The problem is when I press my phone's power button and press it again to start my phone - what i notice is my app is closed and I see the home screen. I want my app to still run even after pressing the power button. ThankYou in advanced!
I think the app is minimized. Long press the home button the app is shown then click the app it will resume.
If by power button you do not mean turning the phone off, you can simply make use of the onresume and onpause functions. More detail on this: http://developer.android.com/training/basics/activity-lifecycle/pausing.html
If this is not working for you, try to log the runtime errors that the app gives and see if there are bugs in the code.

Need clear understanding of Home vs Back events

I would like to know the "idea / use" of the home versus the back button. I mean obviously the home button takes you to the home screen and the back button takes you to the previous screen. What I am trying to understand is what the users / development community expect.
In other words when a user hits home in my application should I handle that event and terminate the application? Is that what the user has grown to expect or just the opposite?
Same for the back button. Do users expect the screen being departed from to be lost much like a web page would be?
What I am getting at is trying to make sure my app behaves consistent with what the user community has grown to expect.
TIA
JB
Home Button will put application in onPause() -> onStop() , again when you relaunch application, the activity will execute the method: onRestart() -> onStart() -> onResume() -> i.e. activity life cycle
and
Back button finishes or kills the current Activity on click of back button and jump back to the previous Activity which is in stack.
Generally I'd say that pressing home is like minimising on a desktop. So I would expect the app to return to where it was.
If it acts like this then I can easily switch between apps if I need to get information from them.
Pressing back should take me backwards through the things I was doing in the app and when I reach the end of the stack it should close.
home button pressing causes an intent that is used by the the launcher app to show itself .
back button is a real event that can be caught within the current app .
in general , home button should hide all apps and go to the launcher , while back button should go back to the previous screen the user saw (finish the activity or dismiss the dialog) , and go to the previous app (task ) in case the current one doesn't have any more screens to show .
The community expects that if you press the home button, your app will go to the background and be resumeable from there. Multitasking is in the core of the Android OS. To finish your activity or app when home button is pressed is unusual to android users.
The back button is when you want to go one step back, like in the browser as you said. If you are know to IOS it will act like when you press the back button there in the top left corner.
Hope this helps
I would like to know the "idea / use" of the home versus the back
button
Let me Discuss for Back Button First.
The back button behavior is inconsistent.
for Users, it is very easy to use.
for Developer, to understand what actually pressing the back button does it isn't so easy.
The back button can perform any of the following actions as Officially said by Android site :
Go back to previous screen (activity)
Dismiss a popup
Terminate a long running process
Close on-screen keyboard
Go to previous page on browser
Exit the running app when on the last activity
Return to previous app when on the last activity and the app was launched through intent from another app
When Problem Occur with BACK button?
An added problem comes when trying to understand when the back button
cancels a running operation and when not. For example, when installing
apps from Android market tapping back takes users to previous screen
and leaves the installation process running in background. I know
there's a rule that back cancels operations that are presented users
as popup progress indicators and any other cases it is used to
navigate. But is that what users expect? Do users have to think before
pressing back to understand what is going to happen?
Home Button
Home button will take users to home screen and swiping in the
multitasking menu will kill the apps if needed. As on ICS on new
phones all the buttons are on-screen the back button could simply get
disabled when user reaches the last activity if the app was launched
from launcher icon. This would make some of the confusion to make away
but still wouldn't solve all the problems.
Finally , Don't Make Users Think Navigation is some what more important. Users should always know where they will endup without thinking.
I don't think there are easy answers for this problem but I think it may help you to find workaround for your problem according to your app.

Categories

Resources