I develop an application of cracking screen i run an android service to showing crack screen on home screen now i want to repair when user pressed back button on five times while our service is running on top and show crack screen how can i handle back button within a service please help me for this how we handle back button in a services like this app https://play.google.com/store/apps/details?id=ultimate.apps.crackscreen2
public void onBackPressed() {
super.onBackPressed();
//Do ur operation here
}
Related
I want to create an app with this ability:when the user press back button.don't close app & stay in running list in settings->application manager->running
& stay in running list when user press home button too.
I like to make an app that there isn't in task manager->active application but there is in settings->application manager->running such as Viber,Tango,Gmail
Add onBackPressed() into your Activity:
#Override
public void onBackPressed() {
moveTaskToBack(false);
}
you can achieve it as follow:
#Override
public void onBackPressed() {
moveTaskToBack(false);
}
to minimize your app use moveTaskToBack(true);
NOTE: don't write super.onBackPressed();
Override onbackpress and do the code for application to go background
Why do you need to keep your app running? If you need to process data while the user is not in your app, you need a Service:
http://www.vogella.com/tutorials/AndroidServices/article.html
Android simple service not starting
I've been trying to resolve this problem for a few days now but I'm having no luck. Here's the issue.
So I have a service window that opens the in-app billing window, works fine in every scenario except one: When the user closes the screen by pressing the HOME button on the phone then re-opens the app. The window is still open but the app crashes in the background. So, the app crashes then the window is still open, user can still react with it.
When the user presses the app account it's just a black screen, nothing else.
I have a service specifically:
This is created in the Activities "onCreate".
ServiceConnectionToBilling mServiceConnection = new ServiceConnectionToBilling();
bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConnection, Context.BIND_AUTO_CREATE);
mInAppPurchasingEngine = new InAppPurchasingEngine(this, this, mServiceConnection);
So my question is, how do I deal with this? I'v been trying to call the Back Button before the user presses the HOME button (as this closes the service window) but of course overriding the HOME button is just fail on Android so I've no idea how to handle this.
PS I have this:
public void onDestroy()
{
if(mServiceConnection != null)
{
unbindService(mServiceConnection);
}
mGameScreen.DestoryEngine();
super.onDestroy();
finish();
}
StackTrace:
http://pastebin.com/gakrL7qV
I know this error, but how on earth do I deal with it? Only happens when closing the app using home button.
The reason why is happening is because you are not unbinding the service in scenarios where onDestroy is not being called like "Pressing Home", notice that pressing home only calls "onPause" and "onStop", hence, in order to fix this issue you need to do what you are doing in onDestroy (unbind service) during "onPause" and bind again "onResume", so when user press home the unbinding method is properly called, and when the activity is reopened the "onResume" will try to bind the service again...
Regards!
i`m writing game for android using libgdx.
And have problem that game controls are near android buttons HOME and BACK.
There is easy way to handle BACK button, but i havent found something for HOME button. All i want - when user accidentally presses HOME button - to handle it and popup dialog if user want to leave game but not to minimize it at once.
You can't handle Home button (nor Lock Screen).
Reference: How to catch Home/Lock Screen button
For anyone who might stumble on this, a plausible solution would be to implement the onPause method in your android launcher
#Override
protected void onPause(){
//do whatever you need to on pause
super.onPause();
}
I know that android does not allow us to catch the home button press; however, I have my own built home screen replacement app and want to just know when the button was pressed to allow animations.
So, my app has just one activity as I do most of my "activities" as canvas drawing so I can have complete control over the visual aesthetics of my app. The problem is if the user navigates to a different page within the app and presses home, nothing happens, since the app is technically already in the same activity.
I want to know when the button is pressed so I can then animate/navigate my app back to the main screen. Also, I know I could accomplish this by having separate real activities however that won't work for what I'm trying to do.
You need to add <category android:name="android.intent.category.HOME"/> to your activity's intent filter in your app's Android.xml
You can take a look at "Home" app in Android SDK samples. They can be downloaded using these instructions.
//overriding method
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
//The Code Want to Perform.
}
});
You can detect when the home button is pressed because onPause() is always called. You are not allowed to override the home button, but the following should work
#Override
protected void onPause()
{
super.onPause();
//code here
}
Of course the problem with using this is that it will be called even if the user is not quitting the app(ie. If they are sent to another application through an intent)
That is the closest that you are going to get to a onHomeButtonPressedListener there are really no ways to do this
Home key press Event Listener
An issue has appeared a few days ago.
I have an application that listen for GPS location. The listener is a background service that works all the time, this service saves data in application level and each activity reads this data. So, when i press back button i am able to catch this event and i can stop the service, but when i press HOME button the service is still working although the application is in background mode and this consumes battery, because the GPS always works. How can i handle this event? I do want to stop all services when the user presses HOME button and start them again when user gets back.
10x
It sounds like you're catching the back button either via an onKey... method or in onStop. You should place your code in the onPause() method to ensure it's used whenever the app gets backgrounded.
You can not handle home button events in your Android application. Google has made it for internal use only.
LINK 1
LINK 2
#Override
protected void onUserLeaveHint()
{
// When user presses home page
Log.v(TAG, "Home Button Pressed");
super.onUserLeaveHint();
}
You could create a OnKeyListener, and check if the pressed key was Home. I never tried it, though.
create a custom activity called customActivity extends Activity now override method(in customActivity) to catch home button event and stop your service(create & start service in application class). Now extends customActivity instead of Activity for any activity_class.
Long press the HOME button, it will enlist the running process, select the one you want and then exit it gracefully.
OR
From Home -> settings -> application -> manage application
you can kill the unwanted process.