1. 程式人生 > >在Activity中關閉另一個Activity

在Activity中關閉另一個Activity

1.對於簡單的兩個Activity 

public class A_activity extends Activity { 

      public static A_activity _instance = null; 

         @Override 
         protected void onCreate(Bundle savedInstanceState) { 
               // TODO Auto-generated method stub 
               super.onCreate(savedInstanceState); 
                ..... 

              _instance = this; 
         } 

   } 

  public class B_activity extends Activity { 

          @Override 
         protected void onCreate(Bundle savedInstanceState) { 
                  // TODO Auto-generated method stub 
                super.onCreate(savedInstanceState); 
                A_activity._instance.finish(); 

          } 
   } 

2.也可以通過ActivityManager 

ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);   
manager.restartPackage(packageName);