How to declare default searchable activity - android

I am trying to implement search in my application.
My application contain 4 activities and I want to add the search dialog only on 3 of them while only one of them (ProductsActivity) will be the default context.
unfortunately while I activate the search I keep getting the following error:
"Key android.app.default_searchable expected String but value was a java.lang.Integer. The default value was returned."
<activity android:label="#string/app_name" class=".AppEntry" android:name=".AppEntry">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".category.CategoriesListActivity">
<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=".product.ProductsActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:resource="#xml/searchable"/>
</activity>
Any idea why ?
Thanks

For default searchable activity you have to put the meta-data tag under the application tag.
<application ... >
<meta-data android:name="android.app.default_searchable"
android:value=".DefaultSearchActivity"/>
<activity android:name=".ProductActivity" >
...
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivityForProducts"/>
</activity>
...
In that example the default application search will be done on the DefaultSearchActivity, while in the ProductActivity the search will be on SearchActivityForProducts. Hope it helps someone.

Shouldn't it be
<meta-data android:name="android.app.default_searchable"
android:value=".product.ProductsActivity"/>
instead of passing the #xml reference there again.

One thing really important here is to correctly name your activities as the Android guidelines explains http://developer.android.com/guide/topics/manifest/activity-element.html#nm
android:name The name of the class that implements the activity, a
subclass of Activity. The attribute value should be a fully qualified
class name (such as, "com.example.project.ExtracurricularActivity").
However, as a shorthand, if the first character of the name is a
period (for example, ".ExtracurricularActivity"), it is appended to
the package name specified in the element. Once you publish
your application, you should not change this name (unless you've set
android:exported="false").
There is no default. The name must be specified.
If you don't put the DOT in your activity name, your search action will only work on the activity you declared as "default_searchable". This little DOT cost us hours so be careful!

Related

Creating a Search Interface in a Android with Kotlin

I am having a hard time figuring out the documentation on creating a search Interface.
My main activity contains the search widget on the app bar but when I perform a search query it does not launch the Searchable Activity; responsible for displaying the results.
Below is my manifest file for the SearchbaleActivity and MainActivity
<activity
android:name=".activities.SearchableActivity"
android:exported="false"
android:label="#string/title_activity_searchable"
android:theme="#style/Theme.MoveApplication.NoActionBar">
<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=".activities.MainActivity"
android:exported="false" >
</activity>
Should my intent-filter and meta-data attributes be in my MainActivity or SearchableActivity?
And even so, my SearchableActivity should launch despite not handling the query, right?
My Android skills are not that great so i'll appreciate a vivid explanation with examples

Android first app, all activities visible in menu

I just created my first Android app, all works fine, but all of the activities are shown on my Android menu. What did I do wrong?
Screenshot: imgur.com/9CmXU
I want to have one icon, directing to MainActivity, not all activities
<!-- language-all: lang-html -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myApps.birthdaymeter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/my_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BirthdayMeter"
android:label="#string/title_activity_birthday_meter" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutWindow"
android:label="#string/title_activity_about_window" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowResult"
android:label="#string/title_activity_show_result" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my manifest, changing logo didn't help
The <intent-filter> tag is used to describe the type of Intents that each Activity will respond to. The "android.intent.action.MAIN" action says that this Activity is an entrance point for your Application (think the main method that a java program requires). The "android.intent.category.LAUNCHER" category tells the OS to display the Activity in your list of Applications. Adding the DEFAULT category is ok, but effectively the same as omitting the <intent-filter> tag completely (which I find to make for much cleaner and easier to read code). You should only be using the <intent-filter> tag with these two actions and categories on the Activity that starts when a user opens your app. If wanted an Activity within your application to be able to respond to some special intents, you would use the tag to define which it responds to.
Here's a link to the google dev pages to help you learn more about Intent Filters.
http://developer.android.com/guide/components/intents-filters.html
Here's the documentation for the <intent-filter> tag. It's not the easiest to understand though.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
And here's the docs for the Manifest file and the Intent class. Both of these are good for reference if you're not sure about which tags to use in your Manifest. Good luck!
http://developer.android.com/guide/topics/manifest/manifest-intro.html
http://developer.android.com/reference/android/content/Intent.html
You phrased your question extremely generally, so I am not sure what to answer. It seems like you haven't called nameOfActivity.this.finish() when you launched another activity
If you post your manifest file I can help a little more, but it looks to me like you have not declared your activities correctly.
It should be setup somewhat like this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="Activity1"></activity>
<activity android:name="Activity2"></activity>
<activity android:name="Activity3"></activity>
</application>
Essentially, create an application declaration, and then include each activity within it.

One android application, two startup view, two two icons

I have my simple notepad application.
It display input text and save button when launching. Everything works fine.
Now I want to keep all app logic, but use "second icon" to launch my app with other initial view (I want to set up numbers only filter on input text).
In other words:
first icon runs general notepad app, user can input everything he wants
second icon runs notpad that accepts only numbers.
Is there any method to create second icon/widget w/e to inform app that it should run in other way?
Add another activity to your application,
also add that activyty to AndroidManidest with
different Icon and with intent-filter
as action=main and catagory=LAUNCHER
Just see:
<application
android:label="#string/app_name" >
<activity
android:icon="#drawable/ICON1"
^^^^^^
android:name=".FirstActivity"
^^^^^^
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:icon="#drawable/ICON222"
^^^^^^^^
android:name=".SecondActivity"
^^^^^^
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Also add another XML for only Number Type Input If needed.

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"/>

How to change the startup activity in android?

I have two activities namely login and calendar in my Application. Currently my startup activity is "calendar". I want to run the login as first activity not calendar.
The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file
Look for that activity tag in the manifest which looks like this
<activity android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.
That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.
Add Intent filter to the Activity in which you want startup.
In your case Modify the AndroidManifest.xml file as follows
<activity android:name=".login"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
remove the intent-filter code from calendar Activity tag in manifest and add it to the Activity you wanna load first
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I mean paste it in the activity you like to run as default.
<activity
android:name="com.example.gridviewimages.AnotherActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where as
From the docs
category -- Gives additional information about the action to execute. For example,
CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while
CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can
perform on a piece of data.
MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
You want the Application element of the Android Manifest file. You can see details here.
Look at the name attribute, this points to the Application class.

Categories

Resources