Atlas91
Atlas91

Reputation: 5904

Android ViewPager guideline

I'm working on a new application in which i want create a intro guideline or wizard or something like tha with a viewpager style. I need display this "Intro" part only the first time i open the application and then never more. In the last tab i want a button and when tapped it brings me to the real MainActivity in which execute the operations. I'm able to create the ViewPager following this example ViewPager tutorial but i can't understand how pass from those fragments to my MainActivity and never more display those tabs. I don't know if my question is clear. I can create a button in the last fragment and onClick open the New activity.. But what about never more display the "tutorial" intro? Thanks

EDIT with button:

startAppBtn.setOnClickListener(new OnClickListener() {         
            public void onClick(View v){
                Intent startApp = new Intent(getActivity(), MainActivity.class); 
                startActivity(startApp);
            }
        });

Upvotes: 0

Views: 137

Answers (1)

user957654
user957654

Reputation:

i think you should use SharedPreferences to save a boolean flag that your first activity "the guideline" activity have been displayed .

and on your button click set the value to true like the following :

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyApplicationPref", Context.MODE_PRIVATE); 
Editor editor = pref.edit(); 
editor.putBoolean("firstTime" , Boolean.TRUE); 
editor.commit();

and in your "guideline" in your onResume method do the following :

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyApplicationPref", Context.MODE_PRIVATE);

boolean firstTime =  pref.getBoolean("firstTime", false); 

if(firstTime == true){
Intent myIntent = new Intent(getApplicationContext() , MainActivity.class);
startActivity(myIntent);
} 

Please give me some feedback .

Hope That Helps .

Upvotes: 1

Related Questions