Options Menu log out/exit app - android

I'd like to have an options menu that includes a logout option to exit the entire app, but none of the logout(), exit(), finish() methods I've tried to incorporate do more than just exit the present activity to show the previous one.
I didn't see anything addressing this on the SOF site, so maybe I'm not approaching a logout in the best way. Optimally, it would also prompt a "Are you sure you want to exit the app" message and flush out particular SQLite data- but I'll worry about that after I get the logout part running.
Any insight?

It's a bad practise to kill the app in your application. However if you really need to do this here is a good solution:
https://stackoverflow.com/a/44208360/6683139

Related

Android: how to know previous app

I have 2 different applications A and B and I want to create a special animation from B to A, that is when A is opened after B was visible. This means that I need to somehow know the previous app after which my app was opened. I can have different scenarios of going from B to A - using Recent Apps (multitasking) button, using Back button, using Home button (application A is a custom home screen). Are there any ideas how to do this? Some functions in ActivityManager might help, but they have comments in documentation saying not to use them for implementing logic and control flow.
Not sure if this will work across different applications, but how about getCallingActivity() or getCallingPackage()?
If that doesn't work, could you pass along some 'extra' data in the bundle when you launch the intent that indicates the launching application?
I managed to figure out how to implement this, its working for me.
I used this answer, but replaced the ActivityManager.getRunningTasks() with ActivityManager.getRecentTasks() supplying RECENT_WITH_EXCLUDED | RECENT_IGNORE_UNAVAILABLE, and took the component name from baseIntent member of the result. The info at index 1 is the one that was running before the current app was opened, irrelevant of the fact how you get back to your app - back button, home button, recents button or opened from another app.
NOTE: This works when your app is started, like in onResume() but doesn't work when your app is closed (when called in onPause()) because the new task is not yet loaded into the activity manager. So if you need to also know to which app are you going then it might be a bit more complex.
NOTE2: Although the documentation tells not to use the API above for any kind of logic and control flow, I saw that the multitasking/recent app's code is doing exactly the same, so in my opinion it should not be as risky as they write it docs.
NOTE3: Don't forget to follow all the steps in the answer I mentioned above, like adding needed permissions, otherwise you will get exceptions. Being part of the system in my case makes it much easier for me.

Android- Application Settings Force Stop

I didn't use any services in my application and closing the application by using
this.finish();
but my application still not stopped properly and it is running in background.when i go to application settings the force stop button is still enabled.
kindly share your views on proper exit of android application.
It's quite possible you have another activity around.
From the Android docs, see Activity.finish():
Call this when your activity is done and should be closed. The
ActivityResult is propagated back to whoever launched you via
onActivityResult().
There's no promise made that the activity will be closed right away on calling finish(), only that this is something that should be done. Usually this does happen right away, but without seeing your project I cannot comment further.
Note that Android, unlike iOS, doesn't really have a well-defined notion of an app. "Apps" can share activities and so on. For example it's not hard, but it's also non-trivial, for an "app" to know that it will go to background or that it has resumed.

Android: UI Recommendations about Exit button in Applications

Are UI recommendations or guidelines somewhere. I am looking for the recommendation from Google but unfortunately I can't find it.
I want to see something like "...do not use exit button in your Applications until you really need it...".
I'm sure that the exit button in android app is not good idea, in general at least. But I want to prove this idea to customers and designers.
I need links with explanations.
This video will help your customers to understand: https://www.youtube.com/watch?v=631T7B8HOv4
Basically, the back button is an exit button. So, there is already an exit button!
Show it to your customer and ask him if he wants to look stupid with duplicate button that takes precious space on a small screen.
His app will never look professional.
General Design Guidelines:
http://developer.android.com/design/get-started/principles.html
Best Practices for User Experience & UI:
http://developer.android.com/training/best-ux.html
Providing Proper Back Navigation(Something you were looking for):
http://developer.android.com/training/implementing-navigation/temporal.html
we used back button as Exit button. Generally on Back button, as per clients req we used to show the default dialog to user, "Do you want to exit app ? ".
Generally clients needs this confirmation because if we press back the app is directly exit from app. so just for confirmation to user clients want this exit dialog be there.
No exit button is iOS philosophy, not android. I suggest you stick with device's back button rather than a UI button to exit your app while asking for confirmation via dialog box or a Toast.

right way to add starting tips in Android app

I am developing an Android application, and I want to show some tips (few slides) for user when applicationis started first time.
I can make an activity and start it in OnCreate method of main activity, or make dialog window.
I want to ask: how to make it in the right way? Can experienced developers advise something, maybe with example?
You have to first make sure that these tips are launched only on first launch of app. I have seen this done by displaying a Dialog, and saving a value to shared preferences (or in sqlite for that matter). On next app launch this value is checked, if it is set, then you don't display the Dialogs.
This seems to be the simplest way. Note that when the app is uninstalled and installed by again the Dialogs will be displayed again.
Sometime we want to give the user ability to see this Dialogs once again. You can do this by setting/resetting the value in shared preferences from the apps settings screen. The user can change the value here and see the Dialogs again on app start.
Just make a Dialog Type Activity and show it automatically at the first time startup of your application.
and also add a help in you menu so that user can see it whenever he/she need help.

Searching for better app widget "workflow"

this may not be your typical question.. but I figured I would give it a shot. I have tried Google searches for this type of question, though apparently I'm using the wrong queries.
So my question is basically how to make my widget "flow" better. Right now this is the flow:
App opens with 'jump' screen, with some directions on how to use it, an information button, and a button that directs you to a configure page (user chooses which pictures they want to view). User is also prompted heavily to configure those pictures before adding an instance of the widget to their screen; or else it won't work.
Once configured, exit the app and visit the homescreen. Add the widget, and the user is presented with a time configuration (how often they want an update to occur). User chooses, hits save, and the widget is added to the screen.
If the user successfully configured in step 1, the widget is added. If, however, they did not do the initial configuration, the widget pops up a toast explaining again that they have to configure.
The user then has to delete the blank widget, re-open the app, configure the images, re-add it, set the time, then good to go.
If successfully added, user can open the time configuration through the widget, or return to the image select by opening it from the app drawer.
Based on that information, does anybody know how I can make this process more simple? Ideas I had were to not allow the widget to be added unless the first configuration takes place.. this is something I could not find any information on :( and/or try to group those two configurations (time/images) into one.
Guess I'm looking for whatever input/suggestions/ideas you folks have. Thanks so much if anybody has any insight onto this! Or if I was just dumb and wasn't able to find certain links that have discussed this already, please point me towards them.
If your app depends on all the configuration, then it should be mandatory. Of course you can make some assumptions in order to simplify the setup, later the user can change those options on some sort of configuration screen.
Actually this is very easy. Based on your question, your widget has a configuration activity declared in the xml file (i.e. android:configure="com.test.widget.act_configure". If the act_configure activity returns RESULT_CANCELED (via setResult(RESULT_CANCELED)) then the widget host cancels its placement.
So you have to check for the required conditions in the widget's configuration activity onCreate method and return OK or CANCELED if they are met or not.
Hope this helps...

Categories

Resources