Need to register for static broadcast (dynamic broadcast)
Give permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Register static broadcast receiver:
<receiver android:name=".MainActivity$MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
All configuration information:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.startactivity">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver android:name=".MainActivity$MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public class MyBroadcastReceiver extends BroadcastReceiver{ //Must be static, otherwise the startup will report an error
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent mainActivity=new Intent(context,MainActivity.class); //skip to MainActivity
mainActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainActivity);
}
}
}
}
Read More:
- redhat7. 5 system service is not started automatically and use systemctl start error: error getting authority: error initializing authority: CO, (the server will restart)
- How to Solve Android Linux5.10 Kernel do_gettimeofday Function Error
- Ubuntu: How to deal with the fatal: the remote end hung up unexpected error of GIT clone Android kernel
- [Solved] Ubuntu 20.04.3 Fail to Start sshd Error: Failed to start OpenBSD Secure Shell server
- [FAILED] Failed to start Raise network interfaces
- [Solved] Linux Error: Failed to start bean ‘webServerStartStop‘; nested exception is org.springframework.
- Android converts a view to bitmap + to handle the black edge of the view with rounded corners
- [Solved] Web server failed to start. Port 8080 was already in use.
- [Solved] Failed to start LSB: Bring up/down networking
- [Solved] VMware error: The module “PhysMem” failed to start.
- [Solved] Go use zoom to connect DM database and start reporting error in Linux
- Failed to start firewalld.service: Unit is masked [How to Solve]
- [Solved] failed to start remount root and kernel file system
- CentOS7 Failed to start LSB: Bring up/down networking [How to Solve]
- Install and start the tftp-server server and possible solutions to Redirecting to /bin/systemctl restart xinetd.service problems
- [Solved] Ubuntu20.04 Error: “Failed to install the following Android SDK packages as some licences have not..“error
- Centos7 Start Error: Entering emergency mode.Exit the shell to continue
- Prompt “entering emergency mode. Exit the shell to continue” if the Linux operating system does not start normally
- How to Solve Error: “Hdaudio hdaudioc0d2: unable to bind codec”
- How to Export All data in DataGridView to Local Excel