An one-time introductory slideshow for all users - android

how do i do it:
The first time each user visits the Apps screen, a slide show will appear instead of a splash screen which will tell the user about various features.
4 slides will come on the very first run of the app. slides will be changed using the swipe gestures
the slideshow will appear only for one time after the very first download.
Check this image as a reference: http://main.makeuseoflimited.netdna-cdn.com/wp-content/uploads/2012/03/HiLauncher6.png?323f2c

All you have to do is store a Boolean variable inside the app using SharedPreferences which will determine whether the slideshow has appeared once or not, if so the don't show it again.
For example:
SharedPreferences sp = getSharedPreferences(MY_PREFS_NAME,
Context.MODE_PRIVATE);
boolean isFirstTime = sp.getBoolean(IS_FIRST_TIME, true);
if (isFirstTime) {
showSlideshow()
} else {
// Go to your main activity
Intent main = new Intent(Start.this, MainActivity.class);
startActivity(main);
finish();
}
Don't forget to set isFirstTime to false once the slideshow has been shown, and store it in the sharedPreferences
Hope that helps

Related

I want to create one time activity

I want to create one time activity window to my Android app.
In the window have two buttons.the buttons are connect to two different pages.
If you download app and run for the first time, you see this window first.then you have to select one button.
When you click the button, you will connect to the target page.
If you close the app, and open it again you can't see the window with two buttons.
The only thing you can see, the window that you previously selected with the button.
This is the thing, I want to do.
I tryied many codes based on YouTube videos.
But I didn't get the progress, that I want.
This the demo app for my course project.
I stuck with this problem.
you can download my project :-
Dropbox - https://www.dropbox.com/s/r4iztx8onqu2ctz/demo.zip?dl=0
Zippyshare - https://www85.zippyshare.com/v/bnXekEoz/file.html
You can save a bit in SharedPrefrence "isFirstRun" set it to true when the application is first run and go through your first activity.. for future run you can check if the "isFirstRun" bit is true skip the first activity.
More about SharedPrefrences here.. https://developer.android.com/reference/android/content/SharedPreferences
In your MainActivity :
SharedPreferences settings = getSharedPreferences("prefs", 0);
boolean firstRun = settings.getBoolean("firstRun", true);
if (firstRun) {
startActivity(new Intent(getApplicationContext(), IntroActivity.class));
}
Create new Activity and named IntroActivity,and in Onclick Button :
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
SharedPreferences settings = getSharedPreferences("prefs", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("firstRun", false);
editor.apply();
finish();
}
});
What you could also do is use install referer receiver then store the value in shared preferences and use that once you open activity https://developers.google.com/android/reference/com/google/android/gms/tagmanager/InstallReferrerReceiver

Start application with second activity

In my android app, When user have successfully login with Facebook and Google Plus then user have one confirmation Activity which have next button in disable mode. While, admin will be enable user from database. If user will be enable from database by admin then confirmation Activity and next button will be enable and user can move to next Activity. When user open app in second time then user will be able to show the confirmation Activity.
I don't know, how to apply this logic :
Scenario:
First Scene:
Splash screen->Login->success->confirmation activity
Second Scene:
ConfirmationActivty->Next button enable
Assuming SplashActivity.java is your main activity
Change your code as shown below
public class SplashActivity extends Activity {
SharedPreferences preferences;
SharedPreferences.Editor prefEditor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = getSharedPreferences("MyPreference", MODE_PRIVATE);
// returns true if value does not exist
// if it's users first time this will return true
if( preferences.getBoolean ("isFirstTime", true)){
prefEditor = preferences.edit();
// changes the value
prefEditor.putBoolean("isFirstTime", false).commit();
}else{
// add your code to open your Confirmation Activity
finish();
return;
}
// rest of your code including `setContentView()`
}
}
You can use SharedPreferences, or File or Database for user's history data and check if the user fulfill your criteria. Then you can let him move from one activity to another. Check these links
SharedPreferences Totorial
SQLite & Content Providers
You can set the visibility of "next" button to "GONE" and make a network call in the background to your server to check if the admin has approved or not. If approved, you can set the visibility of the button to "VISIBLE". And during the network call you can start a progress dialog.Click here to see how to use visibility.
[Update]
you can use something like:
final SharedPreferences prefs = getApplicationContext().getSharedPreferences(
Constants.LAUNCH_TIME_PREFERENCE_FILE, Context.MODE_PRIVATE);
editor = prefs.edit();
profile = getApplicationContext().getSharedPreferences(Constants.PROFILE_PREFERENCE_FILE,Context.MODE_PRIVATE);
if (!prefs.getBoolean(Constants.FIRST_TIME,false)) {
// <---- run your one time code here
Intent intent = new Intent(this,first_screen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
For First Scene :
You should set flag i.e isUserLoggedIn in preferences which will false by default.
After user logged in, set this flag to true.
In LoginActivity onCreate(), check that flag from preferences, if it is true finish the activity and start confirmationActivity else do nothing.
For Second Scene :
Here, you can also maintain the flag isUserConfirmed same as for login. And you can send notification from server to the user, after receiving notification update the flag to true. And enable the button on ConfirmationActivity if the activity is in the foreground.

How do remember that user signed up and take straight to another Activity?

The scenario is if the user downloads the app for first time, I ask them basic questions (say Activity A) and request them to sign up (Activity B).
This is a one time process only after installing the app. After that whenever they open the app, I am planning to take them straight away in to the app (Activity C).
How should I do this? I am a newbie to Android programming. But I am not able to think about this scenario. I don't want to use database.
You need a persistent storage mechanism to save the state of the user (logged in or not). There are various ways you can do this. The easiest is SharedPreference which will store the user state locally. You can also store this information in your remote server and validate user each time she opens the app although this might be going a bit overboard in most cases.
Try using SharedPreferences. In ActivityA in on create check if SharedPreferences contain a certain value which decides if the user is signed up. If it not set or it does not have the required value, redirect the user to ActivityB or else ActivityC
Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref = this.getSharedPreferences("my_prefs", Context.MODE_PRIVATE);
if(pref.contains("MY_KEY") && pref.getBoolean("MY_KEY", false)){ //first stratup or user has not signed in yet
Intent intent = new Intent(this, ActivityC.class);
startActivity(intent);
} else { //already signed up
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
}
setContentView(R.layout.activity_main);
}
Dont forget to save/insert value inside SharedPreferences after the user sign up.
Code:
SharedPreferences pref = this.getSharedPreferences("my_prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
if(sign_up_success){
editor.putBoolean("MY_KEY", true);
editor.commit();
}
The basic flow should be as follows Splash Screen -> OnBoarding Screen(Signup) -> MainActivity On the Splash Screen you need to check for a prefs value lets call it isSignedUp which is false if the user has not signed up. Its pretty straightforward from here. Every time you launch your app you need to check if the preference if isSignedUp is true or false and based on the value show the screen accordingly. So if the value is true that means the user has signed up and show him the main screen else show him the sing up screen.
Use Android SharedPreferences, it can be used to store data which can be used to keep the answers in cache.

How to close app in splash screenn in android

I want my app should be close on splash screen. Actually the whole scenario is from server side if app is blacklisted then app should not open complete, it open show splash screen and show dialog that "you are not authorized " then on click of ok button app should close.. It is not working.. on splash screen why? It is working on Main Activity only
I suggest you should use SharedPreferences and save the state like a boolean isAuthorized set it to true then in your SplashActivity do the following:
SharedPreferences prefs = getSharedPreferences("PREFS_NAME", 0);
boolean isAuthorized = prefs.getBoolean("isAuthorized", false);
if(isAuthorized)
{
startActivity(new Intent(Splash.this, MainActivity.class))
}
else
{
finish(); // or show a dialog that prompts user that you are not authorized....
}
If you have never used SharedPreferences follow this link.
Hope this will help you.

Android splashscreen backstack

I am implementing a splashscreen for a android application. I only want to show the splashcreen once when the app is newly started. After i've done some work I want to go on to the app. If the user then presses the back button I don't want it to return to the splashscreen, I just want the app to exit. How can I implement this in the best way? How do I clear the backstack of the first activity.
If you want to show splash screen only for first time when app launches,
then you can use above solution of share preferences.
But i guess you want to go through following scenarios:
You start the app you get splash screen.
Then you navigate though the app.
Then you come to home screen of you app.
Then you want to exit but splash screen comes.
If you are having this problem then you need to finish splash screen
when you start home activity and also at the end you need to logout or finish the app home activity.
Also try android:launchMode="singleTask" in splash screen activity tab in android manifest.
Use shared preeferences in android and store the value 1st time.. from second time check if value present dont display splash screen
Edit for preferences follow this
When you are going to the second activity after the splash screen, call finish()
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (preferences.getBoolean("firstTime", true)) {
// Show splash screen
// Wait a few seconds.
} else {
// Nothing to do here. Go straight to the second activity.
}
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(
getSupportActivity()).edit();
editor.putBoolean("firstTime", false);
editor.commit();
startActivity(MainActivity.this, ...)
finish();
This way when the user presses back, there wont be any activity in the stack.
Hi, try this code it will help you but it will show the splash whenever you open the app.
public class spash_scr extends Activity {
ImageView t;
//LoginButton b;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.spash_scr);
// bm1=drawable.shineme;
t = (ImageView) findViewById(R.id.textView1);
t.setImageResource(R.drawable.shineme);
RotateAnimation r = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// r.setStartOffset(1000);
r.setDuration(2000);
r.setFillAfter(true);
t.startAnimation(r);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
Intent i = new Intent(spash_scr.this, MainActivity.class);
startActivity(i);
finish();
}
}, 3000);
}
You weren't clear in the exact behavior, so here are some options:
A: You want it to show the splash activity every time the task (app) is restarted, such as after phone reboots, user's manual task closing, or when Android drops it for memory reasons. (This is usually used for branding or licensing logos.) In those cases, launch the splash from the main activity's onCreate(), then Finish() the splash screen to allow the user to return to the main view. That way navigating back won't bring the splash activity back, since it is not in the navigation stack anymore.
B: You want it to show the splash screen the first time the app is launched after installation, but never again. (Usually used for 'welcome' or 'get started' help views.) Use a SharedPreference setting as described in other answers here, or in the Using Shared Preferences documentation. In the case it should show the splash, I still suggest option A for the simplest way to not show the splash screen again for after it is first dismissed after the first launch.
C: An even more, unknown complex navigation? Learn about Tasks and Back Stack and you can make it do pretty much whatever you want.
After opening the new Activity this.finish (); You should do
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
this.finish ();
For that you should use SharedPreferences ,
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("first_time", false))
{
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_time", true);
editor.commit();
Intent i = new Intent(splash.this, otherSplash.class);
this.startActivity(i);
this.finish();
}
else
// Not firsttime Direct it as you wish
}

Categories

Resources