android - 启动 Intent 以在 Android 中将应用程序启动到后台

标签 android background android-intent launch

我在我的应用程序中使用 Wikitude API 1.1 作为 AR 查看器。 Wikitude 的问题是,如果我在手机启动后还没有启动实际的 Wikitude 应用程序,我将在每次启动我自己的应用程序时收到 NullPointerException。

所以我想我是否可以先启动我的应用程序,然后他们检查 Wikitude 是否已安装和/或正在运行。如果没有安装,去market n下载。如果它没有运行,那么我们应该直接在后台运行它,这样我的应用程序就不会失去焦点。

    // Workaround for Wikitude
    this.WIKITUDE_PACKAGE_NAME = "com.wikitude";
    PackageManager pacMan = Poligamy.this.getPackageManager();
    try {
        PackageInfo pacInfo = pacMan.getPackageInfo(this.WIKITUDE_PACKAGE_NAME, pacMan.GET_SERVICES);
        Log.i("CheckWKTD", "Wikitude is Installed");
        ActivityManager aMan = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> runningApps = aMan.getRunningAppProcesses();
        int numberOfApps = runningApps.size();

        for(int i=0; i<numberOfApps; i++) {
            if(runningApps.get(i).processName.equals(this.WIKITUDE_PACKAGE_NAME)) {
                this.WIKITUDE_RUNNING = 1;
                Log.i("CheckWKTD", "Wikitude is Running");
            }
        }
        if(this.WIKITUDE_RUNNING == 0) {
            Log.i("CheckWKTD", "Wikitude is NOT Running");
            /*final Intent wIntent = new Intent(Intent.ACTION_MAIN, null);
            wIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            final ComponentName cn = new ComponentName("com.wikitude", 
                    "com.mobilizy.wikitudepremium.initial.Splash");
            wIntent.setComponent(cn);
            wIntent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
            startActivityIfNeeded(wIntent, 0);*/
        }
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        Log.i("CheckWKTD", "Wikitude is NOT Installed");
        e.printStackTrace();
        //finish();
    }

我阻止评论的部分是启动 Wikitude 的 Intent 。但我总是未能将 Wikitude 限制在后台。有什么帮助吗?先谢谢了。

最好的, 提斯塔

最佳答案

没有“直接运行到后台”这样的东西。

如果他们的应用程序尚未运行,我会通过联系 WIKITUDE 并弄清楚为什么你会得到它来专注于修复你的 NullPointerException

关于android - 启动 Intent 以在 Android 中将应用程序启动到后台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2842248/

相关文章:

android - 将 ListView 选定的项目保存在具有 ViewPager 的 fragment 中

android - 从 Mp4 中提取音频并保存到 SD 卡 (MediaExtractor)

android - "Rate This App"- 手机上 Google Play 商店应用中的链接

android - 通过 webview react native facebook 登录

java - 是否可以在 Android 项目之外使用 Android API?

html - 网站上的两个背景。面临两个问题

html - 更改 Bootstrap 进度条背景(不是进度条,而是进度条背景)

css - 如何根据内容创建高度可变的全宽背景图像?

java - Android 应用程序意外停止

android - 如何通过 android 应用在 google Plus 中共享图像?