home 键防止重启
if (!this.isTaskRoot()) {
Intent mainIntent = getIntent();
String action = mainIntent.getAction();
if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
Android Butterknife
https://github.com/JakeWharton/butterknife
开启蓝牙
Intent turn_on = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(turn_on, 0); if(bluetoothAdapter.enable()) { Toast.makeText(MainActivity.this, "蓝牙已经开启", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "蓝牙开启失败", Toast.LENGTH_SHORT).show(); }
BluetoothGatt通信用的
https://www.jianshu.com/p/a406b94f3188
如何在非activity使用startActivity
public class LoginPwNewextends AppCompatActivity {
public static LoginPwNewloginPwNew;
public static ContextmContext;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityLoginMobile1Binding binding = DataBindingUtil.setContentView(this, R.layout.activity_login_mobile1);
binding.setLogMb(new LogMbViewModel());
loginPwNew=this;
mContext=this.getBaseContext();
}
}
然后再类中
try {
Intent intent =new Intent(LoginPwNew.loginPwNew, TvMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
LoginPwNew.loginPwNew.startActivity(intent);
finish();
}catch (Exception e) {
e.printStackTrace();
}
网友评论