1. 两种重启方式
- 重新启动App -> 杀进程,会短暂黑屏,启动慢
public void restartApp() {
//启动页
Intent intent = new Intent(MainActivity.this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
}
- 重新启动App -> 不杀进程,缓存的东西不清除,启动快
public void restartApp2() {
final Intent intent = getPackageManager()
.getLaunchIntentForPackage(MainActivity.this.getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
2 Gradle sync failed: This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.1 or newer.
AS项目构建时出现此错误,在保证gradle 已经下载了最新的情况下(c:user/administrator/.gradle/wrapper/dist 在此路径有下载的gradle 包)
,可更改plugin 版本。我解决问题的方法是将plugin 版本从 4.1 改成3.4.1
3 在得到acl-connected 时获取到当前蓝牙地址
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
System.out.println(device.getName());
}
}
}
4 android 命令行启动service
am startservice 包名/.service.服务类名