首页 > 解决方案 > 手机重启后重新启动应用程序

问题描述

我想重新启动我的颤振应用程序以在手机重新启动后自动重新启动。我已经在 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);
        }
    }

标签: androidflutterrestart

解决方案


推荐阅读