简体   繁体   中英

Android - webview opens extra activity

I have a android app, in which the main activity calls a function from a external library, which then opens a webview if neccesary.

Opening the webview is no problem. My problem start when people/users close the webview. It appears that the webview (I think, I am not sure though) has opened an extra activity or something on top of the original app that called the external library.

Now users have to close 2 windows, before they can continue in the original app.

Does anyone have experience with this, or knows what's happening here?

public class MainActivity extends Activity
{
    private final String appKey = "Android.Lib.Test";

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        externalLib.Initialize(this, getIntent(), appKey);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

public class externalLib
{
    private static final String TAG = "externalLib";
    private static int messageId;

    public static void Initialize(Context context, Intent intent, String newAppKey)
    {
        Log.d(TAG, "initializing");

        APPKEY = newAppKey;

        if(intent.hasExtra("url"))
        {
            if(intent.getExtras().getString("url") != null)
            {
                Intent webViewIntent = new Intent(context, externalLibWebView.class);
                webViewIntent.putExtra("url", intent.getExtras().getString("url"));
                context.startActivity(webViewIntent);
            }
        }

        if(intent.hasExtra("messageId"))
        {
            messageId = intent.getExtras().getInt("messageId");
            Log.e(TAG, "messageId: " + messageId);
        }
        else
        {
            messageId = 0;
        }
    }    
}

I found out what the problems was. I wanted the webview to load the url, but instead, the browser was opened leaving the webview empty and thus "creating" the extra acitvity. Now the webview loads the url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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