Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Java
//in onCreate
btnOK.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View v){
                         
     Action();//***run this function only once whenever push btnOK ,and when open app again run only once too
    
     Action2();//run normally 

}});

//----Outside
public void Action(){
   //action....
}
public void Action2(){
   //action....
}


THANKS A LOT really :D


actually I found some code but it's only run in once when install
Java
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("firstTime", false)) {
    // run your one time code
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("firstTime", true);
    editor.commit();
}
Posted
Updated 11-Sep-14 19:06pm
v2

1 solution

See http://developer.android.com/training/basics/activity-lifecycle/index.html[^] for details about the life cycle of applications. You can perform actions at specific points by implementing the relevant methods.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900