Pin Code Activity after some actions - android

I need show PIN Code activity after that (we have App with many Activities):
User press hardware button "Home" and go back to App.
List item App Screen go to sleep mode then go back.
What ways do I need to use?

capture home key event(KeyEvent.KEYCODE_HOME) and sleep event(Intent.ACTION_SCREEN_OFF) ,use a variable to record it.
when go back to app activity judge the vaviable and show your PIN code activity.

Related

Reg back button behavior in android

I am having a specific problem in my android app. I have 2 activities and the flow is from
Activity 1 to Activity 2.
I press back button from Activity 2 and then it goes to activity 1. This is great. But in some devices if I stay too long on activity 2(Like for days, I check it once in a while ) , and when I press back button it doesn't go back. So I guess history is cleared by android os for getting more memory.
I know that I can manually override onBackPressed() and achieve the functionality, but I need a perfect solution for this. so it will be like
If the history is all right let android handle back, If history is disturbed then I should be able to handle it.
IS there any way to check any issue with history?

Android Back-Button-Cycle Issue

I'm ware of androids life cycle and that it's not needed to add a "exit" button in the application.
But still, this back button stuff isn't really working out well.
You maybe know this issue from the default SMS-App that android comes with: you open it when you get a new message and exit it using the menu button or something else.
After like 20 times doing this, you then decide to exit the app using the back button, what happens? you have to go back though 20 views. every time you press back you return to the "all messages (by sender)" listview and when you press back there again you return to the message opend 20-1 (message 19). again you press back and return to the listview and again you press back and end up at message 18. till, after40 times pressing back, you finally exit the messanger app.
same happens when for example you got a action bar with a "home" icon which opens the main screen of your app. the user picks a action and the new activity starts. than the user clicks the home button and returns to the main screen. when pressing the back button - no matter if you call finish() in the onButtonBack listener or not, you the user would expect the app to exit, but in fact the app returns to the previous activity which is wrong.
such cycleing may happen for various reasons, thats why - even thought i'm aware of the supposed to be lifecycle of android - i wan't to EXIT (& destroy) the app when pressing back within a defined activity.
calling finish() dosn't help. if there's a previous activity it will re-open it. calling system.exit(0) isn't nice to do.
so: whats the right way to prevent such back-press-cycles and/or exit a application (WITH destruction)?
for better illustration of what i want to achieve: consider A, B, C being activities. a arrow (-->) illustrations a new intent call from the activity leftside of the arrow, rightside of the arrow represents the activity that is called. ex.: A --> B means activity A starts activity B. now here's what i want:
1) A --> B --> C pressBack:--> B pressBack:-->A pressBack:--> Exit
2) A --> B pressBack: --> A pressBack: --> Exit
3) A --> B --> A pressBack:--> Exit
as you see, back works as always, BUT when in activity A it exits the application.
the behaviour i got now is 1) and 2) as above but
3) A --> B --> A pressBack:--> A pressBack: --> Exit
keep in mind, i've already overwritten the onBackPressed listener of activity A with a finish() call. even calling system.exit(0) dosnt work. however, even if it would: its not what i want, i want the REAL way to do it android style - i cant imagine system.exit(0) is best practise.
Well this is the default behavior.
If you have another approach, just implement it.
One approach to deal with this is to use the android:launchMode="singleInstance" for activities that can be launched in a singleton manner (only one activity can exist)
For example, if the SMS page in the SMS app was a singleTop, it would have needed only one back press to remove all the SMS pages. It is a matter of choice
Another more aggressive way would be to finish Activities when you start another activity. Of course, such decision would risk making the app less friendly (android users are not accustomed to this behavior). Nevertheless, if this is used only where it may be considered acceptable then it might be acceptable.
A very acceptable place to do this would be a login screen: Once login is successfull, you start another activity (probably designed for logged in users) and finish the login activity.
Enjoy Finally, in my personal opinion, you can add an Exit button. Users will find it nice.
Check my post: Adding an Exit button to Android Application

Android, difference between LongPress Home and Home

In my app, I've noticed a difference when using the home button.
Ex.
I press app icon, and the app starts op like it should with Activity(A). When I press Home button, the app gets minimized as it should. When I press app icon again, the app resumes with onResume() with Activity(A)
Now for the tricky part.
From the app, when I press my "Start button" another Activity(B) is launched, and focus is changed to the new Activity(B). When I press Home, the app minimizes (like its supposed to).
And now for the problem:
If I press the app icon, my app starts op from the very beginning with Activity(A) where my start button is. (And not with ActivityB which I just minimized)
If I do the scenario over again (Start app - > focus to Activity(B) -> Press home) and this time long press the home button, and the "Recently launched" comes op, and I select my app. Now the focus resumes to Activity(B)
Both Activity(A) and Activity(B) are set to SingleTop.
My question is, why is there a difference when using the different combinations of LongPress home + icon and OneClick Home + icon
First think about this... when you are opening your application ...
your first Screen will be shown may be it is SplashScreen.
and if..you are in Activity A and goes to B and then Press BACK obviously
you will see Activity A.
So now when you Long Press Home button..That shows you recent apps with saves state of last shown Activity..that's why when you open from there..you see Activity B directly without SplashScreen.
And Simple Pressing Home Button Once,you are went to Home Screen from where you are opening Applications Screen which is Launcher Screen..from there If you press any Icon that particular app will be Launched(Means to open the app from its Main Activity that is defined in Manifest with Intent Filter set to Launcher)...That's why opening an app from there will always show you,your SplashScreen.
This is not a Bug,not an Issue..This is how the Android is designed to work.
Same button is used to perform two different events,cause they are related..but It's not like both event performs the same actions.
Continuing to the above scenario, I have an App with Login Screen which takes me to Activity A -> OnClick of some button takes me to Activity B.
when there is a LongPress of Homebutton,and I start another App and stay on it for considerable time like say 5-10 minutes. Then again When i Long Press home button, and return to my Activity - It starts with Activity B .. which is correct.
From Activity B if i press Back key, It does take me to Activity A but there is a Black screen shown. In normal cases, It shows me a a list view of Dynamic XML data.

Different state storage behavior for "Back" vs "Home"

I am still learning the ins and outs of Android development. I am playing around with the Notepad tutorial application to try and get different behavior.
Right now, I want to have the application do the following in the NoteEdit activity:
1) If the Back button is pressed, current state is ignored; basically, it's like an implicit cancel, and you are taken back to the list.
2) If the Home button is pressed, it takes you to the home page as normal. However, if you open the application again, it should go back into the NoteEdit activity in the same state as when you left (IE, if you were partway through an edit, for example).
I removed the "saveState" stuff from onPause, because I don't want to store to the DB unless "Confirm" is pressed (instead, I moved the call to saveState to the confirm button). By doing this, hitting "Back" basically throws out your changes, which is what I want. However, going Home and coming back also throws out your changes, though it does remain in the NoteEdit activity. Both "Back" and "Home" cause the onPause message to trigger, and both cause onResume to trigger (either from clicking on the item in the "Back" case, or by going back into the app in the "Home" case).
Is there a way to have these two events handle saving the state differently? Is it possible to have the Home button store the state (temporarily), while not having the Back button do it?
Thanks in advance!
You need to define an onSaveInstanceState method, but instead of saving to the DB (as in the Notepad sample), save your Activity's state to the Bundle. You then need to recover from the saved state in your onCreate when the passed in Bundle is non-null.

How do I manipulate the Android activity stack?

Here's my two scenarios.
1 -
User opens app for the first time ever from android home screen
User is presented with "first time" screen (backed by first time activity, lets call it A)
User hits back button
user is returned to android home screen
2 -
User opens app for second time
User is presented with the main list screen of the application (backed by a list activity, let's call it B)
User hits back button
User is returned to android home screen
I'm already aware of numerous ways to detect whether it's the first time opening the app or not.
The problem is in having the back button return to the home screen rather than a routing activity that decides which screen to forward to.
Currently My app has an activity to decide where to route (lets call it R) the problem is, My stack either looks like R -> A or R -> B
I want A or B to replace R on the stack when they open, and if the user hits back, then they go to the android home screen, not back to R.
Having a collaborator that sets the view for A and B is also not really workable as B extends androids concrete implementation of a list Activity to get most of its functionality.
Any ideas?
I want A or B to replace R on the
stack when they open, and if the user
hits back, then they go to the android
home screen, not back to R.
Call finish() in R after it calls startActivity() to trigger the opening of A or B.

Categories

Resources