Android If registered launch service activity else launch registration activity - android

I was wondering how to make my app launch the service activity if the user is already registered?, it wont have login activity but registration activity. So the app will start with the registration activity, after registration it will go to the service activity. When user closes the app, how to make it launch again from the service activity and not from registration activity?
How to make it recognize if it is registered go to the service activity and if it is not launch the registration activity(login data will be stored in sharedpreferences I dont know any other way how to do it though in case it disconnects it will have to reconnect again)
I will appreciate any answer, Thanks.

Normally for actions such as this I have an api where users login and if registered information then true is sent back, auto login if shared prefences found. If not then ask them to register. Keeping it in shared preferences isn't bad though, it will save on shut downs and should be fine.

Bearing in mind that if the user clears the data or uninstalls the application, then the shared preferences will be lost and the user would have to re-register to use again as there is no Login Activity.
If this is something that does not bother you then Ashley Alvarado is correct, and shared prefs is fine.
You can use SQLite for storing values as well but it all depends on your app and how you want it.
I would think if you wanted something more serious then I think server side data would be the way to go, but would take some researching.
I'm currently doing something similar and I do use Shared Preferences in my app and SQLite as well. I'm trying to learn different ways to learn as I go.
Hope this helps.

Related

Need to clear shared prefrences while reinstall

My application start with Login. At time of login I am starting one service, and redirecting to another activity as Home. During this i am using SharedPreferences to directly launch Home activity instead of Login activity again. But when I am reinsatlling APK service stops. So i am thinking of clearing SharedPreferences while reinstalling so that apllication launch to Login activity instead of Home. So that user Login to appliaction again and service start again.
A shared preference and sqlite db doesnt get removed on a reinstall.
To delete them, go to
Settings-->Appications-->Manage Applications-->Click on you application-->Click on "Clear Data" on emulator. this will clear the data stored.
When you install an application, there is ACTION_PACKAGE_ADDED broadcast sent, however an installed application does not receive it.
When you uninstall application, it is not even called.
Summary - it's impossible to catch those events from your own application.

Twitter Reauthentication

I have developed one app in which there is option for sharing on twitter.Its working properly fine.Now one requirement came which says that if the app is force killed it should again ask for authentication with twitter so that we can give user id and password again.The main thing is if user want to login to twitter with his new credentials how he will do that.Any idea how to solve this issue.Right now if i am uninstalling the app or clearing the data it is doing authentication but it should do on force killing the app.
You can't detect your app being force killed: https://groups.google.com/forum/?fromgroups#!topic/android-developers/xfkfRc-j4cw
It might be possible to set a flag when your app starts, and clear the flag when your app stops in an orderly way. If the flag is set when your app is starting, then you know it was last stopped in a disorderly way, like being force killed. This method of detection will probably give you both false positives (if someone pulls the battery out of their phone, your flag will probably still be set) and false negatives (if your app considers itself to have been stopped in an orderly way, and is then force killed). This method will surely give you angst and tears unto the fifth generation. Here be dragons, and the dragons will eat you.
You should push back against the requirement.
For your problem, you can clear your tokens when the app starts again, in an onStart(); method for example. So next time the user will use the application after the forced kill, this last wouldn't get any access tokens to work properly and would be consequently "forced" to ask tokens again via a classic OAuth Authentication Flow.
Reauthentications are just like classic authentications. At the end, the Twitter API will give you back the missed (or deleted) access tokens.

how to make a user default option in android as in iPhone

in the first activity of my app i have created some fields as like a registration form and then it goes on to the other activities. Once the user starts the app he must fill all those fields.
when the user closes the app and open's once again, now i should not diplay the registration activity. This must be done until the app is deleted from that device.
I came to know that in iPhone they have an inbuilt option called as User Default, how to create such a thing in ANDROID apps.
What is it called in android, pls explain me....if possible with a sample code or example
What is it called in android
It is called "an if statement".
Your activities, in onResume(), can check if the user has registered by checking your database (or wherever you are storing the data). Then, if the user has not registered, those activities can call startActivity() to launch the registration activity.

Password protect system application android

When a user tries to launch an application I want to suppress that application and then call another application. Example I want the user to authenticate himself before launching a particular system application (settings application etc). The authentication application should pop up every time the user launches the settings application
I know you will have to use broadcast receivers and intents but have no clue how to do it.
Sounds like you should create a "lib" project that have public interfaces that you can use.
Then share them between the apps instead of trying to execute another app?
But what I know this is not possible to actually execute up another app, since this then gives dependency to something that you don't know if it is installed. It must already been started if the intents should work.
Also like the answer before, it could be used for abuse.
Look at this link for more information:
http://mylifewithandroid.blogspot.com/2007/12/playing-with-intents.html
I sort of hope this isn't possible... Launching a different application from the one the user actually clicked? Leaves the door open for abuse.

Launch an activity only the first time the application starts

I need a way to detect if this is the first time the user is ever opening the application, if so, start an activity. Then all previous application launches wouldn't start that activity. I've read in a few places about using preferences to accomplish this. Anyone got any ideas?
Yeah, preferences is the way to go.
Check for the existence of the preference flag, if that exists you have already set, so your application was already started. Otherwise start your welcome activity and set the flag for future.
You can also disable one main activity and enable another one after your intro has run. See: the docs for PackageManager.setComponentEnabledSetting.
what if you have a user who deletes the application data in the device settings. This also removes the sharedPreferences data. The OP said he/she needs a way to determine if "ever" the user has opened an application. Shared Pref is not full proof.

Categories

Resources