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.
Related
I'd like to prevent my application from starting when an Android for Work profile is not available for my application (not yet configured, or deployed on the device). Instead, I'd like to be able to display a Toast like message telling the user to contact his IT administrator. Example of this at the bottom of this message.
Example:
Divide Productivity Suite of application displays this message (mail, notes, etc).
"Configuration from managing application required. Contact your IT admin for details".
Screen Capture
Is there a way to implement this? I've tried to hook into MainActivity onCreate function, or even put it directly in the Application onCreate() function. Hooking code in here seem to still have launched the application (the title bar is displayed despite there's no content displayed).
I was able to figure out how to determine if your Application was running on a for Work profile and display a alert dialog here:
Android for work - How to check if my application is running in the work profile?
Man i can give you specific topic . You can search for services instead of Activities. Activity codes performing only when application is running .
But you can call services everytime without your app is not running.
You can look here
Apparently, this was actually pretty trivial.
In your AndroidManifest.xml, you reference a new Activity that starts your main application. This activity will use the "Theme.Translucent.NoTitleBar"
When you are unable to configure Android for Work profile, use a Toast.makeToast() message to notify your user, then call finish() and return from your onCreate() function.
When you are able to complete Android for Work configuration, start your MainActivity by creating an Intent, set the action and category and then call startActivity() from your initial Activity.
I have two activities: Login and List.
When i log-in i display the list. When user is in the list activity and press the home button. After that clicks on the app icon it brings to login page for some times only. While it should display the list.
How to resolve this?
Your app is pushed out of memory sometimes in order to free memory for other apps. When it happens, app is re-launched when user enters it and first Activity is opened. The only(or not the only) way for you to maintain your app state is to store it somewhere. You could save whether user logged in or not in SharedPreferences and when Login Activity is created you could check this.
Sometimes your app will be killed depending on how much memory other applications need. Your application must save and restore its state in order to behave as if it hadn't been killed.
If you read the section on the Activity Lifecycle in the developer docs, you should understand what you need to do.
I'm developing a Learning Application. In it, I have an Activity where the user can select some applications from a list of all the applications installed on his device.
Now, I'd like to launch my Activity whenever the user launches any of the selected applications from the app list. Basically I'd like to override the selected Activity by my activity. Once the user complete's some task, the user should be returned to the previously clicked Application.
How do I "Capture" this 'Launching other applications' part? BroadcastReceivers? Any example would be highly helpful. I'd be very grateful if anyone points me in the right direction with reference links.
This is very similar to a Lock Apps Application. But in a very badly twisted kind of way.
I know I have to use a background service to monitor the user activity.
You don't intercept arbitrary application launches, if that's what you're after. Doing this silently goes against the Android (or any reasonable) security model.
What you can do is offer an alternative Home screen.
However, if you just have a list view of available applications, nothing stops you from defining custom behaviours within that list activity.
What is the best way to detect when an Android "Application" has been launched from the Home screen/History screen?
Basically, what I'm trying to achieve is force the user to login to certain screens each time they come back to the app (i.e. they have full access to all activities once logged in, but essentially I want them to re-authenticate when they come back to the app via launching on the home screen).
I know similar questions have been asked before (i.e. how to log launches of an app) - but none that I have seen has yet been able to solve my problem. All ideas welcome...
What about
if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY )!=0) {
Log.d(TAG, "Called from history");
}
?
This uses a simple Intent flag.
What is the best way to detect when an Android "Application" has been launched from the Home screen/History screen?
You can't, AFAIK.
Basically, what I'm trying to achieve is force the user to login to certain screens each time they come back to the app (i.e. they have full access to all activities once logged in, but essentially I want them to re-authenticate when they come back to the app via launching on the home screen).
Please use a sensible, user-friendly login system. For example, if you feel that their login credentials are stale based upon time, then force them to log in again. You can do this by checking the credentials in onCreate(), and if they are stale, call startActivity() to launch your login activity (or pop up your login dialog, or whatever is your means of logging them in).
Of course, an even better approach is to skip the login entirely. Unless this is a "password safe", a banking app, or something else that needs higher-than-average security, you do not need them to log in, and your users will get irritated if they feel that your login requirement is unnecessary. Most mobile applications do not require authentication.
Forcing a login based upon how they reached the activity is user-hostile. You are telling users that deign to use their phones for things other than your app that they are second-class citizens.
simply create a stump activity that doesn't have a content view and launches other activities on application start
e.g. put the following into onCreate:
Class<?> myclass;
if(isTimeForActivity1){
myclass = Activity1.class;
}else if(isTimeForActivity2){
myclass = Activity2.class;
}
startActivity(new Intent(this, myclass));
finish();
Try to look at the "OI Safe" application which has a well designed solution (I don't know if the code is well designed too, but, you'll look :p)
We can launch the app in two ways, 1 is form the app, clicking on device back button till we reach the android home screen and launching the app or 2nd is from the app we can click the device home button and then we can launch.
How can we differentiate these to launches? In 2nd type launch onrestart will be called, onrestart will be called in some other cases also.
I want to do something in the 2nd type of launch.
Can any one tel me how to do this...
Thanks in advance.
When it comes to what happens when the activity is started, you may want to look at the following link in the developer site.
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
You may want to code based on the lifecycle of the activity rather than if the application was pushed to the background by the home key vs. by the back key. There could be different reasons the application was pushed to the background or closed. This is the expected way to handle application events.