简体   繁体   English

onNewIntent没有被解雇

[英]onNewIntent not being fired

I'm using intent filter for catching a custom scheme for my app: 我正在使用意图过滤器为我的应用程序捕获自定义方案:

<activity
    android:name=".activities.MyActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:label="@string/title_my_activity"
    android:launchMode="singleTop"
    android:noHistory="true"
    android:screenOrientation="portrait">

    <!-- myapp://app.open -->
    <intent-filter android:label="@string/my_intent">
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="myapp" />
        <data android:host="app" />
        <data android:host="app.open" />
    </intent-filter>
</activity>

In my activity I override: 在我的活动中,我覆盖:

@Override
protected void onNewIntent(Intent intent) {
    Log.d("DEBUG", "New intent!");
    super.onNewIntent(intent);
}

but this is never called...where am I wrong? 但这从未被称为...我在哪里错了? Is noHistory flag necessary? noHistory标志是否必要? If I remove that, I've two copies of the same activity on the stack. 如果删除它,那么我将在堆栈中拥有两个相同活动的副本。

Below code is working fine for me 下面的代码对我来说很好

<activity android:name=".MainActivity"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="myapp" />
            <data android:host="app" />
            <data android:host="app.open" />
        </intent-filter>
    </activity>


 public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = new Intent(this,MainActivity.class);
    startActivity(intent);

}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.d("DEBUG", "New intent!");
}}

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

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