What method logical for lock my home screen button android - android

I'm making a lock screen application on Android, I've gotten an event when the home button is pressed but I can't figure out how or what method to prevent the user from exiting the application via the Home button..
I use the method when the Home button is pressed then call the application back but this way there is a delay and still exits the application, maybe someone knows and can give me a little idea or technical for this case..
Thanks in advance..
here my button home event in log
action:android.intent.action.CLOSE_SYSTEM_DIALOGS,reason:homekey
my recent app event in log
action:android.intent.action.CLOSE_SYSTEM_DIALOGS,reason:recentapps

You can't. The home button is a system button, there is no way to override the behavior of it. This is because any app that prevents you leaving it, other than a kiosk app, is pretty much malware by definition- you should never prevent the user from leaving your app. And if you're building a kiosk app, you'd be making it a launcher (I'd also highly recommend not using React Native for that, as the performance is low and a launcher needs to be lightweight to lead quickly.

Related

Differentiating between going to home screen after showing browser due to ad or going back to app from browser due to ad

I've an app that should always start from the initial activity when its icon on home screen is pressed.
I've managed to make this work in every situation by finishing the current activities when the application was going to be exited.
But there's a point in the app where this is not possible unless I ruin user experience a lot, which is if the user opens an ad offered by the app and then either goes to home screen (via home button for example) or press back button to keep on using the app.
In both cases the following events are fired: onAdLeftApplication-> onAdClosed-> on Resume (although as how I understand documentation onAdClosed shouldn't fire in the case of opening the browser, but well... it happens).
With this I find no way to differentiate between the 2 cases, although there might be an event, that would allow to differentiate them-
Think the easiest way to solve this problem is to always force that if the icon is pressed what is fired is never onResume, always onCreate, this way I don't have to worry about the app not starting from beginning for whatever, by default it's going to do that.
But maybe what I'm mentioning is not possible anyway, so maybe some event like the one I'm mentioning might help with this problem. I'll happily listen to any recomendation about that.

Android studio App home button and re open

Android studio home button problem.
I have so many activities, when I press home buttom in any activities.
Then if I restart my app.
it started from splash activity(logo activity).
However, I want to start this from activity where I pressed home button.
Can anybody figure this out?
By default, Android handles this behavior. When you press the home button, the app should go to background and at the next time when you open it, it should start from where you left off. But, Android's memory management is designed to automatically terminate minimized apps that have not been accessed in a while when memory is needed for newly launched apps.
If there is enough memory available and still your app gets terminated, that means you are not using the API's correctly. Please read this [article] to know how to handle onPause() and onResume() to achieve this behavior.

Android application which you cannot close

Is there any programming tricks that makes your application unclosable?
For example: You touch the back or the home button, but they don't do anything.
Or at least is there a way that your application blocks some applications to open?
I don't think you can stop user from moving your application to background unless it's some kiosk mode app. And the method to do that is to become device administrator and override all possible callback methods - home, back, settings, notification area etc.
If you just want to prevent your app from getting closed due to user activity you can show a persistent notification. This will allow you app to run in background even if user presses home button.
Make a launcher/Home screen app:
When users click the home button, your app will show.
You control ALL apps that can be started
On devices running android lolipop, you can use the screen pinning option available in your ROM.
NOTE: This is ROM feature, you don't have to do anything in your app.
See this great article about it.
yes its to get set the on backpressed method to.
moveTaskToBack(true);
finish();
Are you trying to hack in android OS ? Let me tell you that android apps are sandboxed, which isolates your app data and code execution from other apps.

how to prevent use of HOME button in android and ios?

I am working on an application in which user should be able to use only one application,
he should not be able to switch application using HOME button,
the app. should be closed only when user presses the close button..
I have managed to override return button, don't know how to disable HOME button.
This is not possible to disable the Home Button in android When application is in the background because it might some application always disable the home button if it's possible. So this is the reason developer can't disable the home button when app in background. But In the Activity, you can intercept the home button.
In Activity you can disable the Home key in android. It work till Android 3.x only.
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
TGMCians is right.
Android will not let an activity and its services run completely alone on your device.
Using Override you can capture button clicks (home, back and menu) when your activity is in the foreground. If an activity/service has full control from the background you would not be able to switch for an incoming sms, e-mails, phone calls, etc either.
Personally I think its dangerous to override the home and back button together, if the activity hangs at some point, you can not get out of the app unless you restart the phone.
Personally, I do override the back key for exit, or return to main screen events, but leave the home button alone.
This is not possible using code at all on iOS, ever.
One usage of HOME button is for emergency situation.
Any house, apartment ... they all have an emergency method, like emergency door (exit), glass breaker (axe, bat ...); it saves life.
Similarly, on Android/iOS phone, HOME button saves users' lives (well, kind of). If HOME button is dead, the phone is considered dead as well as required an instant reboot for refresh. The button was designed for such a purpose, so that developers can't messed-up with everything.
Personally, I'm kinda of being thankful for Android/iOS framework team and whoever thought of this situation on HOME button. It saves my development so many times. I suggest you should think and consider the worst case possible if HOME button is not working in your app; for example, app fails to function as normal, HOME is disabled, so how to back to HOME screen, how to switch to other apps?...
The code provided by TGMCians is not working on 4.0+.
In case, you are working on Android framework, such as building ROMs, building frameworks for manufacturers, ... grep the source code with KEY_HOME and trace inner-depth to find how it works and disable it.
actually, it is possible to block the home button using the next methods:
use of security holes, at least on old android versions. this is done on some locker apps. i think some still work even on newer android versions, but it's a risk and it might be buggy on some devices. i know that "widgetLocker" and "Picture Password Lockscreen" try out those holes. i'm not sure how well they work now with them. best solution of becoming a lockscreen is #2 .
make your app a launcher app, which will handle the home button (user must confirm it of course). an example of such an app is "MagicLocker" , and in fact any launcher app...
using a rooted device. i have no idea how to do it, but i think it's very possible.
not quite a blocking method, but you could have your app full screen and on top (using the TYPE_SYSTEM_ALERT window layout type) , so home button won't be captured, but the user won't see what's going on behind your app. the downside is that any other button won't be captured by your app, since it's not really on the foreground.

Adobe Flash Builder Flex Mobile Android: Avoid that user can close the app

I am developing an app for android. It is not always clear to me when the app will be terminated by the OS. Sometimes it happens when you press the back button and sometimes when you press the home button. What is the logic behind this?
My app must be keep activated during a long period (when you run it the app must stay resident). Also another question is if it is possible to popup when an event comes in and activate the screen and bring it to the front.
Does somebody made this already? Or is there more information about this (how to do it). Search the internet but doesn't find some useful things.
Pressing the Back button on the main activity will finish and exit the app.
Pressing the Home button will pause and leave the app in the background, it will return to the previous state when it's restored.
Override the onBackPressed() method on the main activity if you don't want it to quit when the back button is pressed.
If you want an event to occur when the screen is shown, override the onResume() method and do the checks and event required in there.
Being that your answer is with Flex the issue is that you need to listen to the stage's keyDown event.
stage.addEventListener(KeyboardEvent.Key_DOWN, yourHandler);
Then you need to response to the back button and inhibit this - if your intent is to stop the back button.
private function _onStage_keyDownHandler(event:KeyboardEvent)
{
if(event.keyCode == Keyboard.BACK)
{
event.stopImmediatePropogation();
event.preventDefault();
//your code here
}
}
And one more moment - android can close your app when it thinks that it need more memory for more recent apps.
And you may need to use native extensions or even develop your app in java if you want to implement reliable resident behavior.
Update: java service+ air ui example:
http://www.jamesward.com/2011/05/11/extending-air-for-android/
end of update
And you must know that air apps eat at least 30mb of memory(if they are empty and do nothing), normally they will start from 50-70mb. I guess that no user will wish to allow another 70mb of his memory-hungry device to be eaten by something not critical.
And for automatic maximizing of your window you may need root access.

Categories

Resources