I have implemented the following code but my SearchActivity::OnCreate is not getting called. Can someone please tell me what I'm missing?
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kace.SearchTest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data android:name="android.app.default_searchable" android:value=".SearchActivity"/>
<activity
android:name=".Search_testActivity"
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" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</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>
/res/xml/searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/description" >
</searchable>
SearchActivity.java:
public class SearchActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction()))
{
String query = intent.getStringExtra(SearchManager.QUERY);
int q;
q = 10;
}
}
#Override
protected void onNewIntent(Intent intent)
{
// TODO Auto-generated method stub
super.onNewIntent(intent);
}
}
Android guides explicitly says:
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
Which is in your case NOT TRUE. Because you don't want to search in MainActivity but in SearchableActivity. That means you should use this ComponentName instead of getComponentName() method:
ComponentName cn = new ComponentName(this, SearchableActivity.class);
searchView.setSearchableInfo(searchManager.getSearchableInfo(cn));
try this :
Update your AndroidManifest.xml as:
<activity
android:name=".Search_testActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:value=".SearchActivity"/>
</activity>
<activity android:name=".SearchActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#layout/searchable" />
</activity>
</application>
put searchable layout in layout/ instead of /res/xml/:
layout/searchable.xml :
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/description"
android:searchMode="showSearchLabelAsBadge"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:voiceLanguageModel="free_form"
android:voicePromptText="#string/search_invoke"
android:searchSuggestSelection=" ? "
/>
For more working example see my answer in this post
And
You can download working example from SearchWidgetExample
Found the answer! In the onCreate method of my main activity (Not the search activity), I added the following lines:
SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
SearchView sv = (SearchView)findViewById(R.id.searchView1);
sv.setSearchableInfo(searchableInfo);
Try adding default_searchable setting under your "source" activity:
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchActivity" />
In short, you need default_searchable setting for the "source" activity and searchable setting for the "search result" activity (your SearchActivity class).
Related
I have an app A and an app B, I'm trying to open an app B activity from app A, which is not the main activity.
I know there are already lot of answers on this subject, but I can't manage to make any of these work, this is why I'm asking for help.
First here is the "simplified" manifest of the app B (the one that has to be opened) :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rlaville.gestionsav" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".Vues.CreationSav"
android:windowSoftInputMode="stateHidden"
android:noHistory="true">
</activity>
<activity android:name=".Vues.GestionSav" android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Vues.StatSav" android:noHistory="true">
</activity>
<activity android:name=".Vues.ModifierSav" android:noHistory="true" android:windowSoftInputMode="stateHidden" android:exported="true" >
<action android:name="com.example.rlaville.gestionsav.MODIFY_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
<provider
android:name=".Donnees.SavDataProvider"
android:authorities="com.example.rlaville.gestionsav.Donnees.SavDataProvider"
android:exported="true"
></provider>
</application>
</manifest>
The activity I want to open is ModifierSav, so I did put an intent filter inside of it as it is said to do in every tutorial.
Then I've tried these methods in the other app :
Directly calling the intent filter name :
Intent i = new Intent("com.example.rlaville.gestionsav.MODIFY_ACTIVITY");
i.putExtra("CurrentSavID", itemId);
startActivity(i);
Or using a packageManager :
public boolean openSavApp(Context ctx, String packageName, long itemId){
PackageManager manager = ctx.getPackageManager();
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.putExtra("CurrentSavID", itemId);
ctx.startActivity(i);
return true;
}
that I tried to call like this
openSavApp(getActivity(), "com.example.rlaville.gestionsav.MODIFY_ACTIVITY", itemId);
What am I doing wrong? What should I do to be able to open this specific activity from the other app?
You have missed <intent-filter> tag.
<activity android:name=".Vues.ModifierSav" android:noHistory="true" android:windowSoftInputMode="stateHidden" android:exported="true" >
<action android:name="com.example.rlaville.gestionsav.MODIFY_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
change this to
<activity android:name=".Vues.ModifierSav" android:noHistory="true" android:windowSoftInputMode="stateHidden" android:exported="true" >
<intent-filter>
<action android:name="com.example.rlaville.gestionsav.MODIFY_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Update:
you are getting null intent because you are not providing the correct package name here.
you have provide here this package name which you mentioned in manifest tag.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rlaville.gestionsav" >
public boolean openSavApp(Context ctx, String packageName, long itemId){
PackageManager manager = ctx.getPackageManager();
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.putExtra("CurrentSavID", itemId);
ctx.startActivity(i);
return true;
}
<intent-filter>
<action android:name="com.example.rlaville.gestionsav.MODIFY_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
You've forgot to put action and category inside intent-filter block.
can't fire activity on onListItemClick() in ListActivity with buttons in list?
if i touch the button, i could not get into the referred activity. it just stays there in that page even on click.
public class Intro4 extends ListActivity{
String classes[] = {"Entertainment","TextPlay","Current-Affairs"};
public static int correct,wrong,marks;
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese= classes[position];
try {
Class ourClass = Class.forName("com.SVS."+cheese);
Intent ini= new Intent(Intro4.this,ourClass);
startActivity(ini);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Intro4.this,android.R.layout.select_dialog_item,classes));
}}
Manifest is:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Intro1"
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=".Intro2"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.SVS.INTRO2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Intro3"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.SVS.INTRO3" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Intro4"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.SVS.INTRO4" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Entertainment"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.SVS.ENTERTAINMENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.SVS.TEXTPLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.SVS.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Here:
String classes[] = {"Entertainment","TextPlay","Current-Affairs"};
Current-Affairs is not a valid java identifier. see Using Java Naming Conventions for more details.
And make sure all activities Entertainment,TextPlay,... is declared in AndroidManifest.xml
i got the answer.. in java clas..
Class.forname("com.svs.blabla")
not
("com.SVS.blabla")
i.e., package name should be in lower case.
When my app starts up i see the title bar and the application name with a white activity.
Even though my mainactivity is a splash screen, it does not start at first, but after 2 seconds of this Title bar and white activity. How do i disable this.
thanks for the help!
Splash.java
`public class Splash extends Activity {
#Override
protected void onCreate(Bundle parameter) {
// TODO Auto-generated method stub
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
super.onCreate(parameter);
Thread timer= new Thread()
{
#Override
public void run()
{
try
{
//Display for 3 seconds
sleep(3000);
}
catch (InterruptedException e)
{
// TODO: handle exception
e.printStackTrace();
}
finally
{
//Goes to Activity StartingPoint.java(STARTINGPOINT)
Intent openstartingpoint=new Intent("com.vault.beta.MAINACTIVITY");
startActivity(openstartingpoint);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
`
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vault.beta"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".MainActivity"
android:label="Vault - Login" >
<intent-filter>
<action android:name="com.vault.beta.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Screen"
android:label="Calender" >
<intent-filter>
<action android:name="com.vault.beta.SCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MenuList"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.vault.beta.MENULIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Password"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.vault.beta.PASSWORD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".EditNote"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.vault.beta.EDITNOTE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Remove the theme of the main activity
android:theme="Theme.Holo.NoActionBar"
I have created a splash activity for my app. I am trying to redirect from my Splash activity to the Starting Point activity using AndroidManifest.xml but its not working. The Splash class loads up, and then it doesn't redirect to the Starting Point. And it doesn't give any errors either.
So can you please help me figure it out.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myapp.Splash"
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="com.example.myapp.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapp.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Now I have also tried
<activity
android:name=".Splash"
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=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapp.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
So what can I do here. I am not getting redirected from Splash to my Starting Point.
Splash Code
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
}
Add this code to your Splash.java
Thread timer = new Thread(){
public void run(){
try {
sleep(2000);
} catch (Exception e) {
// TODO: handle exception
} finally{
Intent i = new Intent(Flash_Activity.this, StartingPoint.class);
startActivity(i);
}
}
};
timer.start();
}
You are never calling anything to change the activity from your splash to the starting point. This thread will do that.
Use this easy way to redirect to acitvity
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
finish();
}
},2500);
I've implemented the action bar found here https://github.com/johannilsson/android-actionbar and it works beautifully. However, I've added a search button and can't get it to show the search dialog. I followed the Google's search dialog tutorial to set my project up, but the dialog just won't show up. Any help?
Manifest:
<activity android:name=".HomeActivity" android:label="Intelicase Mobile" android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
<activity android:name=".SearchActivity" android:launchMode="singleTop">
<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=".SearchActivity" />
<!-- this activity enables the search dialog to initiate searches in the SearchableActivity -->
<activity android:name=".OtherActivity">
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
Action Bar setup:
ActionBar actBar = (ActionBar) findViewById(R.id.actionbar);
actBar.setTitle("Dashboard");
actBar.setHomeAction(new ActionBar.IntentAction(HomeActivity.this, intent, R.drawable.ic_title_home_default));
intent = new Intent().setClass(this, CaseEvidenceActivity.class);
actBar.addAction(new ActionBar.IntentAction(this, intent, R.drawable.ic_title_export_default));
intent = new Intent().setClass(this, OtherActivity.class);
actBar.addAction(new ActionBar.IntentAction(this, intent, R.drawable.ic_title_search_default));
OtherActivity:
public class OtherActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
onSearchRequested();
}
}
searchables.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="Intelicase Mobile"
android:hint="Search Intelicase" android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
Action Bar Setup
actionBar.addAction(new SearchMP());
private class SearchMP extends AbstractAction {
public SearchMP() {
super(R.drawable.title_search);
}
#Override
public void performAction(View view) {
onSearchRequested();
}
}