Android fatal exception unable to resume activity - java

Hi everybodi!
I'm new to Android programming and am trying to create a QR code reader app with Zxing. When I start my application in my phone, it gives me this error message. The app is started, after I push the button and then this is thrown... What is the problem?
Here is my code: This is the MainActivity
package com.example;
public class MainActivity extends Activity {
private Button scan;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan= (Button)findViewById(R.id.button1);
scan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("App","Scan unsuccessful");
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
And this is my AndoridManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:noHistory = "true"
android:name="com.example.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="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>

Related

How to implement search interface in android using searchView widget

I have completely followed the Docs on this regard.
I made searchable.xml file
added new activity to handle the query once search is made.
I updated the manifest file accordingly.
My problem is that the new activity is not being called at all as if there is something wrong with the manifest.
Here's the xml file:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/search_hint" >
</searchable>
Here's the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sultanraja.notes">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SearchResultsActivity">
<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=".NoteActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here's the new activity code meanwhile:
public class SearchResultsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_results);
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
Toast.makeText(getApplicationContext(),"your Query is " + query, Toast.LENGTH_SHORT).show();
//use the query to search your data somehow
}
}
}
The Toast is never happening and a breakpoint in the onCreate method is never reached.
what is the problem?
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
if(list.contains(query)){
adapter.getFilter().filter(query);
}else{
Toast.makeText(MainActivity.this, "No Match found",Toast.LENGTH_LONG).show();
}
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
// adapter.getFilter().filter(newText);
return false;
}
});
I found the problem in the manifest file:
I added the following:
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultsActivity" />
this part was added to mainActivity and that was not part of the documentation.
thanks.

when i want to test my app with a real device the app doesnt start

I've been trying to test my app where I'm implementing a G+ sign in and when I run it in the emulator with Android Studio the app runs but says that I need to update Google Play Services.
I've been struggling to do that so I thought that I would just test it on a real device but when I do the app doesn't start/run. When I go to settings and apps on device I can see that the app is installed but it doesn't show up in the app drawer or anywhere else.
I get this exception under my run tab in the bottom left corner:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.madchallenge2016edwindaniel.upbirdwatchers/.LoginActivity } from null (pid=20620, uid=2000) not exported from uid 10154
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1948)
at com.android.commands.am.Am.runStart(Am.java:463)
at com.android.commands.am.Am.run(Am.java:108)
at com.android.commands.am.Am.main(Am.java:81)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:276)
at dalvik.system.NativeStart.main(Native Method)
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<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:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar" />
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
</application>
Here is the code of my launch activity:
package com.madchallenge2016edwindaniel.upbirdwatchers;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;
public class LoginActivity extends AppCompatActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
private GoogleApiClient mGoogleApiClient;
private SignInButton mSignInButton;
private static final int RC_SIGN_IN = 9001;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//Background
getWindow().setBackgroundDrawableResource(R.drawable.login_background);
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
SignInButton mSignInButton = (SignInButton)findViewById(R.id.sign_in_button);
mSignInButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
// ...
}
}
});
}
//Start sign in
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
} else {
// Signed out, show unauthenticated UI.
// updateUI(false);
}
}
#Override
public void onConnected(Bundle bundle) {
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
public void setmSignInButton(SignInButton mSignInButton) {
this.mSignInButton = mSignInButton;
}
}
After editing my manifest file according to the answer I got, my app now runs.
This is what my updated manifest file looks like:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar"/>
</application>
You missed Intent filter in android manifest
Please replace your manifest with below code...
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<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:exported="true"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
</application>
Intent filters show when to launch this activity. usually you will have one activity with intent filter that is to show that it is first activity when application is launched.

how do I get value from BroadcastReceiver activity to main activity

I want get the install referrer value in my MainActivity. For that i am using two class
1) MainActivity
2) ReferrerReceiver
I got received install referrer value successfully in ReferrerReceiver class, i tested this using Toast control.
But i can not able to pass this value to MainActivity from ReferrerReceiver.
Bellow is i tried code. please any one help me.
Thanks for advance.
1) MainActivity.java
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv1 = (TextView) findViewById(R.id.tv1);
Intent in1= getIntent();
String ldString = in1.getStringExtra("number");
tv1.setText(ldString);
}
}
2) ReferrerReceiver.java
public class ReferrerReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {
return;
}
Bundle bundle = intent.getExtras();
String phoneNumber = bundle.getString("referrer");
Intent i = new Intent(context, MainActivity.class);
i.putExtra("number", phoneNumber);
context.startActivity(i);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myreferrer.in"
android:versionCode="7"
android:versionName="1.0.6" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<receiver android:name="com.myreferrer.in.ReferrerReceiver"
android:enabled="true">
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This was i implemented in my project. its working for me. Use this code
(1) MainActivity.java
public class MainActivity extends Activity {
TextView tv1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
}
public static void log(Context context, String string) {
if(string!=null) {
Toast.makeText(conte, "Referrer value is."+string, Toast.LENGTH_LONG).show();
tv1.setText(string);
}
}
(2) ReferrerReceiver.java
public class ReferrerReceiver extends BroadcastReceiver {
String referrer,rawReferrer;
public static String getReferrer(Context context) {
// Return any persisted referrer value or null if we don't have a referrer.
return context.getSharedPreferences("referrer", Context.MODE_PRIVATE).getString("referrer", null);
}
#Override
public void onReceive(Context context, Intent intent) {
try {
// Make sure this is the intent we expect - it always should be.
if ((null != intent) && (intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))) {
// This intent should have a referrer string attached to it.
rawReferrer = intent.getStringExtra("referrer");
if (null != rawReferrer) {
// The string is usually URL Encoded, so we need to decode it.
referrer = URLDecoder.decode(rawReferrer, "UTF-8");
Toast.makeText(context, "ReferrerReceiver." + referrer, Toast.LENGTH_LONG).show();
MainActivity.log(context,"\nRaw referrer: " + rawReferrer +"\nReferrer: " + referrer);
MainActivity.log(context,referrer);
// Persist the referrer string.
context.getSharedPreferences("referrer", Context.MODE_PRIVATE).
edit().putString("referrer", referrer).commit();
} else {
Toast.makeText(context, "ReferrerReceiver." + referrer, Toast.LENGTH_LONG).show();
MainActivity.log(context,referrer);
context.getSharedPreferences("referrer", Context.MODE_PRIVATE).
edit().putString("referrer", referrer).commit();
}
} else {
Toast.makeText(context, "ReferrerReceiver intent value is null.", Toast.LENGTH_LONG).show();
MainActivity.log(context,referrer);
MainActivity.log(context,"intent value is nulll");
context.getSharedPreferences("referrer", Context.MODE_PRIVATE).
edit().putString("referrer", "intent value is nulll").commit();
}
}
catch (Exception e) {
//Toast.makeText(context, "ReferrerReceiver catch"+e, Toast.LENGTH_LONG).show();
MainActivity.log(context, e.toString());
}
}
}
(3) AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myreferrer.in"
android:versionCode="7"
android:versionName="1.0.6" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<receiver android:name="com.myreferrer.ReferrerReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"></action>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
(4) sample link:
https://play.google.com/store/apps/details?id=your_package_name&referrer=Welcome
You are using
Intent in1 = new Intent();
String ldString = in1.getStringExtra("KEY");
you are declaring new intent which is wrong, and also key you put is also wrong, which should be number
Replace it With,
Intent intent= getIntent();
String ldString = intent.getStringExtra("number");
you have declared your activity as"single Task" in Manifest;so if an instance of your
activity is already launched the system will create (NewIntent) to re_lunch your
activity.try to put this code before onCreate():
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// NOW getIntent() should always return the recent
setIntent(intent);
}
to get all the time the newest intent with the new extras.

Try to resolve ActivityNotFoundException

I try to share a post on google+ but I obtain this Exception. The Activity that creates the Exception is ExampleActivity and this is its code:
public class ExampleActivity extends Activity implements OnClickListener,
ConnectionCallbacks, OnConnectionFailedListener {
private static final String TAG = "ExampleActivity";
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
#Override//onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities("http://schemas.google.com/AddActivity","http://schemas.google.com/BuyActivity")
.build();
// Progress bar to be displayed if the connection failure is not resolved.
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Launch the Google+ share dialog with attribution to your app.
Intent shareIntent = new PlusShare.Builder()
.setType("text/plain")
.setText("Welcome to
the Google+ platform.")
.setContentUrl(Uri.parse("https://developers.google.com/+/"))
.getIntent();
startActivityForResult(shareIntent, 0);
}
});
}
#Override//onStart
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
#Override//onStop
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
#Override// onConnectionFailed
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
// The user clicked the sign-in button already. Start to resolve
// connection errors. Wait until onConnected() to dismiss the
// connection dialog.
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
// Save the result and resolve the connection failure upon a user click.
mConnectionResult = result;
}
#Override //onActivityResult
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
// #Override
// public void onConnected(Bundle connectionHint) {
// String accountName = mPlusClient.getAccountName();
// Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
// }
#Override //onDisconnected
public void onDisconnected() {
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
}
#Override//onConnected
public void onConnected() {
// TODO Auto-generated method stub
}
#Override
public void onClick(View arg0) {
}
}
This is the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.applicazionescienza"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.applicazionescienza.Menu"
android:label="#string/app_name"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.applicazionescienza.Informazioni"
android:label="#string/title_activity_informazioni" >
</activity>
<activity
android:name="com.example.applicazionescienza.Regolamento"
android:label="#string/title_activity_regolamento" >
</activity>
<activity
android:name="com.example.applicazionescienza.Gioca"
android:label="#string/title_activity_gioca" >
</activity>
<activity
android:name="com.example.applicazionescienza.Livello"
android:label="#string/title_activity_livello" >
</activity>
<activity
android:name="com.example.applicazionescienza.Punteggio"
android:label="#string/title_activity_punteggio" >
</activity>
<activity
android:name="com.example.applicazionescienza.TwitterActivity"
android:label="#string/title_activity_twitter"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="casa"
android:scheme="app" />
</intent-filter>
</activity>
<activity
android:name="com.example.applicazionescienza.FacebookActivity"
android:label="#string/title_activity_facebook" >
</activity>
<activity
android:name="com.example.applicazionescienza.ExampleActivity"
android:label="#string/title_activity_example" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
The Exception say: No activity found to handle Intent(act=android.intent.action.SEND....
Someone can help me?
Try and clean the project, uninstall your app from device and reinstall.

Search dialog doesn't show up

I wanted to implement a search dialog in my android project. and I don't understand what I'm missing on showing the search dialog to the user.
Here's the manifest for the Activity that suppose to launch the search:
<activity
android:name=".ArrowsActivity"
android:label="#string/title_activity_main" >
<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=".Searchable" />
</activity>
Here's the manifest for the Searchable Activity:
<activity
android:name=".Searchable"
android:launchMode="singleTop"
android:label="#string/title_activity_searchable" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
Here's the searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="#string/search_hint"
android:label="#string/search_label">
</searchable>
Searchable class:
public class Searchable extends ListActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchable);
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
// doMySearch(query);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_searchable, menu);
return true;
}
}
SO.. how do I pop the search box to the user> what am I missing?
Just call onSearchRequested() somewhere, this will start the search activity declared in your manifest.

Categories