在Android的启动时启动应用程序 [英] Start Application on Startup in Android

查看:199
本文介绍了在Android的启动时启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试推出的主要活动(这是唯一的活动),命名为MainActivity的Andr​​oid操作系统启动时。该应用程序被安装在内部存储,但它说,不幸的是,这个应用程序(应用程序名称)已停止。我使用的是引导接收code如下

我MainActivity code在java文件

 公共类BootU preceiver延伸广播接收器
{    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
            意图I =新意图(背景下,MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(ⅰ);
    }
}

AndroidManifest.xml中

 <使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>      <接收机器人:启用=真正的机器人:名字=BootU preceiver。
    机器人:权限=android.permission.RECEIVE_BOOT_COMPLETED>    &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
            <类机器人:名字=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>
     < /接收器>


解决方案

最后,寻找了一段时间,对于一些一谁是困在这里后做了正确的事情。你需要做的是注册在一个单独的包中的onReceive函数,我渐渐在logcat中的错误是ClassNotFound的,因为我放在code在我MainActivity类别及其封装。当我没有改变的onReceive功能,新的软件包应用完美地工作。

I am trying to launch the main activity (which is the only activity) named as "MainActivity" when the Android OS starts. The app is installed on the internal storage but it says Unfortunately, The app(Name of app) has stopped. I am using the Boot Receive code as below

My MainActivity code in .java file

public class BootUpReceiver extends BroadcastReceiver
{

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

AndroidManifest.xml

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

      <receiver android:enabled="true" android:name=".BootUpReceiver"
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

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

解决方案

Finally, did the right thing after searching some time, For some one who is stuck up here. What you have to do is register the onReceive function in a separate package, what i was getting the error in Logcat was Classnotfound as i placed the code in my MainActivity class and its package. As soon as i did changed the onReceive function to new package the application worked flawlessly.

这篇关于在Android的启动时启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆