Android浏览器链接共享并不总是更新URL

Android浏览器链接共享并不总是更新URL,android,android-intent,Android,Android Intent,对于下面的代码,我在共享从Chrome浏览器到我的应用程序的链接时遇到问题 工作原理:在Chrome中,我点击三个点并选择共享。然后我得到一堆应用程序图标,然后点击我的。URL在我的应用程序中正确到达 什么不起作用:在Chrome中,我再次点击三个点。由于我刚刚与我的应用程序共享,我的应用程序图标显示在右侧的“共享”旁边。当我点击它时,应用程序会报告以前的URL,而不是当前的URL 在任何时候,如果我长期这么做,URL都是正确的。我的意思是,选择共享,然后从可共享图标列表中单击我的应用程序 我需

对于下面的代码,我在共享从Chrome浏览器到我的应用程序的链接时遇到问题

工作原理:在Chrome中,我点击三个点并选择共享。然后我得到一堆应用程序图标,然后点击我的。URL在我的应用程序中正确到达

什么不起作用:在Chrome中,我再次点击三个点。由于我刚刚与我的应用程序共享,我的应用程序图标显示在右侧的“共享”旁边。当我点击它时,应用程序会报告以前的URL,而不是当前的URL

在任何时候,如果我长期这么做,URL都是正确的。我的意思是,选择共享,然后从可共享图标列表中单击我的应用程序

我需要更改什么才能通过两个共享路径从Chrome获得正确的链接

我的代码可以在这里找到:

以下是有趣的文件这是一个全新的空AndroidStudio项目,我只更改了以下三个文件:

ActivityMain.java

package com.mmccoo.browsershare;

import android.content.Intent;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.util.Iterator;
import java.util.Set;

public class MainActivity extends AppCompatActivity {
    public static final String TAG = "com.mmccoo.mytestmay2";

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

    @Override
    protected void onStart() {
        super.onStart();

        TextView textView = (TextView) findViewById(R.id.maintext);

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Set<String> keys = bundle.keySet();

            String str = "";
            Iterator<String> it = keys.iterator();
            while (it.hasNext()) {
                String key = it.next();
                str += (key + ":" + bundle.get(key));
            }
            textView.setText(str);
            Log.d(TAG, "bundle: " + str);
        }

        if (intent.getAction() == Intent.ACTION_SEND) {
            String newweburl = intent.getStringExtra(Intent.EXTRA_TEXT);
            Log.d(TAG, "got url " + newweburl);
        } else {
            Log.d(TAG, "other intent");
        }
    }
}
AndroidManifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

             <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain"/>
            </intent-filter>

        </activity>
    </application>

</manifest>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.mmccoo.browsershare.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/maintext"
        android:text="Hello World!" />
</RelativeLayout>

也许第二个意图来自onNewIntent?@ArtemMostyaev,这不会改变任何事情。我很有希望。如果您的活动已在运行,则getIntent中的意图不会被新的替换。它只传递到方法中。也许第二个意图是通过onNewIntent?@ArtemMostyaev实现的,这不会改变任何东西。我很有希望。如果您的活动已在运行,则getIntent中的意图不会被新的替换。它只传递到方法中。