我已经在manifest里面设置好了,可是按下搜索按键后就是不会调用onNewIntent方法,这是咋回事?照理说设置了android:lauchMode后就会调用这个方法了的。
我的AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.leu.myapplication" >
<uses-permission android:name="android.permission.READ_CONTACTS" />
<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"
android:launchMode="singleTop">
<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.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
</application>
</manifest>
下面是我demo的源码,是一个使用SearchView的demo。
理想按下搜索键后应该显示一个输入文字的Toast
https://github.com/Leu-Z/MyApplication2
According to the API description, the key to your problem lies in the return value of
onQueryTextSubmit()
: Only by returning false can SearchView initiate an intent. If true is returned, it is considered that the submit has been processed by the listener itself.Modify the return value to fasle to solve the problem. Already tested and passed :)
I also posted your code for other people’s reference.
Try setting singleInstance