Android session handling - java

How do I manage a session in an Android app after the user successfully logs in? Should I use SharedPreferences or static variables to store the session info?
The user must log in every time the app launches too.

Try to use Account Manager. It was designed for it. Here is a tutorial for it.
Anyway it is not recomended to use preferences for it, because at the end it is plain XML file, so anyone can steal data from it. Also it is not recomended to use static variables, because you never know when your process will be killed. For example somebody could call to your phone and android could kill your app and restart it after call ends.

Related

Android to always run activity

I'm making an Android app that act as an IOT host (I use serial communication and send it to Arduino). Is there a way to always set Android to run this activity (never sleep & always inside the activity)? It is important for it to not leave the activity since all the control and db access is done through it. So far what I've found already available is kiosk app in which it act as a launcher with limited app and such but none of the lock the android to an activity.
Thanks for answers & comment!
If you're curious :) The reason I use Android is that it needs a control panel UI and connection to a database, using RPI and other stuff would just get it to be more expensive.
there a way to always set android to run this activity (never sleep & always inside the activity)?
Not really. You are somehow looking for kiosk mode, or you can make your app acting as launcher (but it all depends on use case - if your app is only one on the device then this is all fine, otherwise you would need to put a lot of efforts to jail user)
it is important for it to not leave the activity since all the control and db access is done through it.
It sounds like your app architecture is just designed wrong.

How to block application launch in Android

I want to create an application in Android that will show the devices list of applications and then allow the user to select which apps they want to be restricted access to for a certain period of time.
I am aware there is an Android Application named "AppBlock" but i don't know how this works.
You select the app, the period of time and then it doesn't allow you to open the app.
You cannot actually block start of another application.
The only way that I see it is possible: you need to save the list of applications Info in your app that need to be blocked with the time when it need to be blocked. Implement a service that runs "forever" and detects started applications.
Refer to this answer about how to do it. On each detection you should check if application present in your database and if the time now says it need to be blocked. If it is - close the application. Refer to this answer for learning how to do it.
That is global architecture I think you should follow.
To Build App Block u need the following things
1-Accessibity services (AS)2-Forground Services (FS)
BY AS you will be able to stop activity that you have in your bloker list
FS will alive your application context that help to find block app

How to add shortcut on home screen when app gets install

I know it's not the best practice, but it is a requested feature (e.g. for business apps). When the App gets installed, I need to automatically place it on the home screen. I saw a lot of code on the internet, but all of the code only works on button click when the app starts. But I need to place a shortcut on the homescreen immediately after the app is installed and before the app starts. Is there a way I can achieve this?
PS: To make the question more clear: The app will be distributed without Google Play Store, so that's not an option.
Thanks for your help!
Best regards,
Robin
You can't run any code in your application before the user starts your application for first time during to restrictions since Android 3.1. Check this for more information
That's an optional feature of the Market app, not of the apps themselves. When designing an application , it does not receive a broadcast about itself being installed.
the first time the app launched can create it.
You can achieve that by creating a method in your main activity and call this method from oncreate and create a boolean variable andsave it in shared preferences

How to clear memory when user Log off the app

I am making an app that user has to Log in and connect to a Server. And i have maps, pins, a lot of bitmaps and variables, however, I want variables and other unnecessary to be cleared on user Log off
What i want is like a restart the app, like when the user open the app for first time.
I heared about:
android.os.Process.killProcess()
but not sure when it actually does and how i can call it...

Methods to be performed when app 1st installs android

Hi guys I have been looking around for the answer to this but have come up with nothing, I would like to have an activity that asks the users for their details and then send them details to an external database after they first install the app. Does anyone have any suggestions on how to create an activity that will only be used when the app is launched for the 1st time. Cheers to anyone who can help
Save a flag in shared preferences that you set after completing the activity. You can actually save this flag anywhere, as long as you have it in some sort of persistent storage. Then on load, check in that activity if the flag exists (you can do this in onCreate), if it does, launch an intent to another activity.
Create a file or store a persistent property at the first boot.
Check for the existence of that file/property at every boot.

Categories

Resources