android - 手机重启后重新启动应用程序
问题描述
我想重新启动我的颤振应用程序以在手机重新启动后自动重新启动。我已经在 android native 中完成了此操作,但现在我希望在我的颤振应用程序中具有相同的功能,并在颤振中尝试了这种方法,但它在那里不起作用。任何帮助将不胜感激
这是我的 android 本机代码,用于在移动重启后重新启动应用程序。
在清单中
<receiver
android:name=".BroadcastReceiver.RebootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
重启接收器类:
public class RebootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())
) {
Intent mainIntent = new Intent(context, com.expo.exposports.ExpoMainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainIntent);
}
}
解决方案
推荐阅读
- html - 如何使用 express.js 获取选择选项的值?
- c# - 如何组合多个 Func<> 委托
- php - 如何在 Laravel web.php 路由中使用 php 箭头函数
- javascript - 如何将等待与“$.get”一起使用?
- php - 当代码在云中运行时,我下载文件的 php 脚本只是在浏览器中显示它,但在我的本地服务器上运行良好
- ios - 如何使用 SwiftyJSON 解析类型不明确的数据?
- r - 如何在R中绑定多个列
- python - 根据另一个数据集中的元素位置过滤熊猫数据帧的快速方法
- javascript - 从每月或每周或每天或议程更改视图会使应用程序对大日历做出反应
- java - 反应堆跳转到错误的调度程序?