我正在使用intent filter为我的应用程序捕获自定义方案:
<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>在我的活动中,我覆盖了:
@Override
protected void onNewIntent(Intent intent) {
Log.d("DEBUG", "New intent!");
super.onNewIntent(intent);
}但这永远不是called...where,我错了吗?是否需要noHistory标志?如果我去掉它,堆栈上就会有两个相同活动的副本。
发布于 2018-05-14 22:16:14
下面的代码对我来说很好用
<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!");
}}https://stackoverflow.com/questions/50331836
复制相似问题