简体   繁体   English

Android createChooser出现在Activity的前面

[英]Android createChooser appear in front of Activity

I'm hoping one of you fine folk may be able to help me out with a little issue I am having whilst using Android Intent.createChooser(). 我希望你们中的一员能在使用Android Intent.createChooser()时遇到的一个小问题帮助我。 I am learning as I go with my application so I apologise if I have the wrong end of the stick with how this should work! 我在学习应用程序时正在学习,因此如果我坚持到底应该如何工作,我深表歉意!

I have been following a number of tutorials and have implemented some code which starts an Intent.createChooser() to share a picture to social media. 我一直在关注许多教程,并实现了一些代码,这些代码启动了一个Intent.createChooser()以将图片共享给社交媒体。 The code that I have used works fine in that I am able to share the picture as I intended, my issue is that when the code is run my main activity (or any activity I call the code from) appears to close and the chooser appears in front of the homescreen or any other applications I may have open. 我使用的代码可以正常工作,因为我能够按预期共享图片,我的问题是,当代码运行时,我的主要活动(或我从中调用代码的任何活动)似乎关闭并且选择器出现在主屏幕或我可能已打开的任何其他应用程序之前。 The effect that I was hoping to have, and the one which seemed to be apparent in the tutorials, is for the chooser to appear in front of the running activity (eg as it does for the gallery). 我希望获得的效果以及在教程中似乎很明显的效果是使选择者出现在正在运行的活动的前面(例如,对于画廊而言)。

I am using LibGDX meaning that I have had to use an interface to call the android function that executes the chooser code (in my AndroidLauncher java file). 我正在使用LibGDX,这意味着我不得不使用一个接口来调用执行选择器代码的android函数(在我的AndroidLauncher Java文件中)。 The interfaces all work fine but I wasn't sure if that may have a bearing on the way in which this code operates. 所有的接口都可以正常工作,但是我不确定这可能与这段代码的运行方式有关。 I have also played around with swapping to a new activity to implement the chooser code, which I had moved from the AndroidLauncher. 我还尝试过切换到一个新的活动,以实现选择器代码,该代码已从AndroidLauncher移走。 This had the same end result. 这具有相同的最终结果。

Any advice on how to make the chooser appear in front of my application would be greatly appreciated! 任何有关如何使选择器出现在我的应用程序前面的建议将不胜感激! The code which implements the createChooser is included below: 下面包括实现createChooser的代码:

public void ShareHandler(){
    String type = "image/*";
    String mediaPath = Environment.getExternalStorageDirectory().getPath()+"/Smile.png";
    createShareIntent(type, mediaPath);
}

private void createShareIntent(String type, String mediaPath)
{
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType(type);
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(share, "Share to"));
}

Android Manifest: Android清单:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.game"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="25" />

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


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme">
        <activity
            android:name=".AndroidLauncher"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".FacebookServiceHandler" />

        <meta-data
            android:name="come.facebook.sdk.ApplicationID"
            android:value="@string/facebook_app_id" />

        <provider
            android:name="com.facebook.FacebookContentProvider"
            android:authorities="com.facebook.app.FacebookContentProviderxxxxxxxxxxxxx"
            android:exported="true" />

    </application>

</manifest>

Thanks in advance, Ben. 预先感谢,本。

If 如果

android:name=".FacebookServiceHandler"

is the activity, that handle the social media sharing of the picture, i would expand that to something like this: 是活动,处理图片的社交媒体共享,我将其扩展为以下内容:

<activity
    android:name=".FacebookServiceHandler">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".AndroidLauncher">
    </meta-data>
</activity>

This will tell the programm, that the AndroidLauncher is the parentactivity and should make it appear in front of your activity. 这将告诉程序,AndroidLauncher是父项活动,应使其出现在活动的前面。

Thank you for the suggestions, I have now solved my issue. 谢谢您的建议,我现在已经解决了我的问题。 It turned out that my code was working correctly all along and the issue I was experiencing was as a result of an exit statement within my Core (LibGDX) java code. 事实证明,我的代码一直都能正常工作,而我遇到的问题是由于我的Core(LibGDX)Java代码中的退出语句导致的。 Essentially when the startActivity(Intent.createChooser(...)) was called, a dispose function within my core files was also being called. 本质上,当调用startActivity(Intent.createChooser(...))时,还调用了我核心文件中的dispose函数。 This dispose function contained the exit command and was causing the application to finish. 此处理函数包含exit命令,并导致应用程序完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM