How to add quick search box to our application? - android

How to add quick search box (QSB) to our application?

Check this page on more info about the QSB in android.
and add this to your activity in the manifest
<activity android:name=".MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>

Related

Android App Manifest Setup

Hello I am fairly new to Android App Development and was looking at some example code here. I understand that the manifest xml here states that by pressing the app to launch the map but I wanted to implement a login as well. I was wondering if anyone here had any advice in terms of how popular apps format this? Do they have a login as their launcher or the application itself? Thank You!
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It seems you look to change the launcher activity
<activity android:name=".LoginActivity" android:label="#string/title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can put the login activity that way

the MainActivity show the up icon(the left-facing caret)

I am working under an android application which I want to provide the Up Navigation, follow the guide, I made the following configuration:
<activity
android:name=".ui.MainActivity"
android:launchMode="singleTask" android:theme="#style/OverlayActionBarTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity
android:name=".ui.RouteActivity"
android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
</activity>
<activity
android:name=".ui.SearchPoiActivity" android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
</activity>
<activity
android:name=".ui.PoiListActivity" android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
</activity>
However I have to questions here:
1 The repeat codes
As you can see I have to add the following xml for each activity, is it possible to declare it once?
android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
2 The main activity of my application .ui.MainActivity have the up icon !
Tha's to say even I enter my application the first time and at the MainActivity, the left-facing caret is visible. I do not think this is normal.
Then I wonder does I miss anything?

Android Search Activity and android:launchMode="singleTop"

I have a single activity in my app that uses a SearchView to search (see manifest-- the search intent is intercepted).
However, when I press search, nothing happens. The activity never re-starts itself. So, I removed android:launchMode="singleTop" from my activity and then it started re-starting itself and "working." However, it is preferable to have singleTop for me so that the activity only has one instance. Why is this not working when I have singleTop?
<activity
android:name="com.brianco.andypedia.MainActivity"
android:label="#string/app_name"
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>
<meta-data android:name="android.app.default_searchable"
android:value=".MainActivity" />
I don't know if this answers your question, but this page shows a simple searchview example with ActionBar Compat (it is the new google library compatible for the old Android versions)
You need to process your search intent on onNewIntent besides onCreate.

android search view on another Activity

I'm Creating a Search View Sample Project;
I have 3 Activities:
MainActivity(Direct you to search Activity)
SearchActivity(You can see search View and type whatever you want)
SearchResultActivity(Will Process your Search request)
and in Manifest file I have
<activity
android:name="com.example.searchsample.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity android:name=".SearchResultActivity">
</activity>
if I press search button; I can see the new SearchActivity Opens ;
if I move the intent-filter Part from .SearchActivity to .SearchResultActivity; I no longer can Search anything; (Because the .SearchResultActivity never run)
how can I solve this Problem;
I want, when I Press the search button, see result on .SearchResultActivity

Android Manifest File Not Picking Up Default Launch Activity

If on run/debug configuration, if I specify a launch activity, then my app runs fine, but when I select 'Launch Default Activity' I get "No Launcher activity found!" error from android adb despite the fact that I have specified the launch activity in my manifest file. I'm using android 2.1.
I've tried refreshing the file/project, clean and rebuild, deleting the file and re-writing it, creating a new project and copy/pasting all the code across and doing Android Tools -> Fix Project Properties. I've tried Android Tools-> Rename Application Package, which prompts me to update the project launch configuration (to which I say yes, but it still doesn't fix the problem).
I've also tried different devices. My Home activity extends another activity and is in its own Home.java file in my src folder. This is what my manifest file looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geogreenweb.localvore"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="#drawable/icon"
android:label="#string/general_app_name"
android:debuggable="true">
<meta-data android:name="android.app.default_searchable"
android:value=".localvorebeta6" />
<activity android:name="com.geogreenweb.localvore.Home"
android:label="#string/general_app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Quit"
android:label="Quit">
</activity>
<activity android:name="com.geogreenweb.localvore.InSeason"
android:label="In Season">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.List"
android:label="A - Z">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Local"
android:label="Local"
android:configChanges="orientation"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Details"
android:label="Details">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Search"
android:label="Search">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Map"
android:label="Map"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Help"
android:label="Help">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="7" />
</manifest>
UPDATE: I changed one of the activity labels, and the different label appears in the app, so the changes to the manifest file are being picked up, but still I get the No Launch Activity error
UPDATE 2: I managed to solve the problem by creating a new project in the end, but only if I select the option to create an activity when making the new project, then copy/paste in the rest of the stuff into the project
if you remove the :
<action android:name="android.intent.action.SEARCH" />
it will launch normally.
i don't know why .. it just worked for me. i'm still searching why?!!
UPDATE 1:
i found this:
No Launcher activity found, despite being declared in manifest.xml
still don't know why? .. still searching for it.
UPDATE 2: GOT IT!
http://developer.android.com/guide/topics/intents/intents-filters.html
A filter has fields that parallel the action, data, and category fields of an Intent object. An implicit intent is tested against the filter in all three areas. To be delivered to the component that owns the filter, it must pass all three tests. If it fails even one of them, the Android system won't deliver it to the component — at least not on the basis of that filter. However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another.
in our case this means that the system sends an intent with the MAIN action and LAUNCH category. it finds an with the following:
MAIN action ..............[ pass ]
LAUNCH category .... [ pass ]
SEARCH action .........[ fail ]
but .. if you put the SEARCH action in another , the containing the MAIN and LAUNCHER criteria passes.
The only thing I can think of is the lines
<activity android:name="com.geogreenweb.localvore.Home"
Try using just
<activity android:name=".Home"
instead
Try adding the following to your main launcher Activity right next to the launcher category element.
<category android:name="android.intent.category.DEFAULT"/>

Categories

Resources