android.app.Activity.finishAffinity()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(414)

本文整理了Java中android.app.Activity.finishAffinity()方法的一些代码示例,展示了Activity.finishAffinity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.finishAffinity()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:finishAffinity

Activity.finishAffinity介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = JELLY_BEAN)
public void shouldCallFinishOnFinishAffinity() {
 Activity activity = new Activity();
 activity.finishAffinity();
 assertTrue(activity.isFinishing());
}

代码示例来源:origin: com.uphyca/android-junit4-robolectric

/**
 * 
 * @see android.app.Activity#finishAffinity()
 */
public void finishAffinity() {
  mActivity.finishAffinity();
}

代码示例来源:origin: kingargyle/adt-leanback-support

public static void finishAffinity(Activity activity) {
    activity.finishAffinity();
  }
}

代码示例来源:origin: iqiyi/Neptune

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void finishAffinity() {
  mOriginActivity.finishAffinity();
}

代码示例来源:origin: bitmovin/bitcodin-android-demo

@Override
 public void onClick(View v) {
  SharedPreferences.Editor mSharedPreferenceEditor =
    context.getSharedPreferences("bitcodin", Context.MODE_PRIVATE).edit();
  mSharedPreferenceEditor.remove("current_api_key");
  mSharedPreferenceEditor.commit();
  ((Activity)context).finishAffinity();
 }
};

代码示例来源:origin: leftcoding/GankLy

private static void startActivityOrFinish(final int finishType, final Activity thisActivity,
                     final Intent intent, final Integer requestCode,
                     final Bundle bundle) {
  if (requestCode == null)
    thisActivity.startActivity(intent);
  else if (bundle == null)
    thisActivity.startActivityForResult(intent, requestCode);
  else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    // TODO 注意:低于api16 时
    thisActivity.startActivityForResult(intent, requestCode, bundle);
  } else
    thisActivity.startActivityForResult(intent, requestCode);
  switch (finishType) {
    case FINISH_SINGLE:
      // finish当前activity
      thisActivity.finish();
      break;
    case FINISH_ALL:
      // finish目标activity外的所有activity
      // TODO 注意:低于api16 使用 finish() 代替 finishAffinity()
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        thisActivity.finishAffinity();
      } else
        thisActivity.finish();
      break;
  }
}

代码示例来源:origin: leftcoding/GankLy

case FINISH_ALL:
  thisActivity.finishAffinity();
  break;

代码示例来源:origin: stackoverflow.com

@Override
public void startActivity(Intent intent) {
  if(MyApp.mBackStackActivities
    .containsKey(intent.getComponent().getClassName())){
    if(android.os.Build.VERSION.SDK_INT >= 16) {
      Activity activity = MyApp.mBackStackActivities.get(intent.getComponent().getClassName());
      // finish the activity as well as all the below Activities.
      activity.finishAffinity(); // supported from API 16
    }else {
      // loop through all the below activity and finish it
    }
  }
  super.startActivity(intent);
}

代码示例来源:origin: jorgegil96/All-NBA

private void restartApp() {
  Intent intent = new Intent(getActivity(), MainActivity.class);
  PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 12345,
      intent, PendingIntent.FLAG_CANCEL_CURRENT);
  AlarmManager mgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
  if (mgr != null) {
    mgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 100, pendingIntent);
  }
  getActivity().finishAffinity();
}

代码示例来源:origin: leftcoding/GankLy

case FINISH_ALL:
  thisActivity.finishAffinity();
  break;

相关文章

Activity类方法