在ActivityA中关闭另一个ActivityB

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); 

你可能感兴趣的:(android开发)