android - 如何在启动时启动/启动应用程序 Android

标签 android android-activity launcher launching-application

我想在我的平板电脑启动时启动我的应用,以便我的应用的主要 Activity 是用户在启动平板电脑时首先看到的内容。
我读过 LauncherActivity 但我不明白如何使用它。
任何人都可以为此提供建议、链接或教程吗?
LauncherActivity 是最好的方法还是有替代方法?

最佳答案

这些代码行可能对你有帮助...

第一步:在AndroidManifest.xml中设置权限

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

第 2 步:在接收器中添加此 Intent 过滤器

<receiver android:name=".BootReceiver">
    <intent-filter >
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>

第 3 步:现在您可以从 Receiver 类的 onReceive 方法启动应用程序的第一个 Activity

public class BootReceiver extends BroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {
       Intent myIntent = new Intent(context, MainActivity.class);
       myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(myIntent);
   }

}

关于android - 如何在启动时启动/启动应用程序 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10428510/

相关文章:

android - 标记为 "SingleTask"的 Activity 已提前

android - 在 Android 中不使用 intent extras 将字符串传递给另一个 Activity

linux - 如何将应用程序快捷方式添加到 Oracle Linux 7 启动器面板

android - 自动更新 Android 启动器

java - Eclipse 为 Android 开发有这么多问题?

android - 难以创建我自己的自定义 View

android - 如何将我的应用程序的所有声音静音?

iOS swift : LaunchScreen doesn't show image

android - 如何使用VrPanoramaView加载Cardboard Camera标记的照片?

android - 运行牛轧糖的华为手机出现安全异常