判断是哪一个acitivity在活动Preferences的使用

@Override
public void onResume() {
    Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
    e.putString("last_activity", getClass().getSimpleName());
    e.commit(); 
    super.onResume();}

 

public class StartActivity extends Activity {
    @Override  
    public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 
   // get last open Activity
           String lastActivity = PreferenceManager.getDefaultSharedPreferences(this).getString("last_activity", ""); 
                  if (last_activity == MyActivity2.getSimpleName()) {
                              startActivityForResult(new Intent(this, MyActivity2.class)); 
                            } 
                 else if (last_activity == MyActivity3.getSimpleName()) {
                   startActivityForResult(new Intent(this, MyActivity3.class));
                        }
                    else { 
                         // assume default activity  
                       startActivityForResult(new Intent(this, MyActivity1.class)); 
                              }  
           }   
       public void onActivityResult() {  
             // kill the activity if they go "back" to here        finish();    }}

 

你可能感兴趣的:(活动,Go)