I have a Map activity in a fairly complex layout. As such, I can’t simple search using the map’s search function in that activity without making a bad window (and crashing the app, I would need onSearchRequested to use a different context, but it doesn’t accept parameters.)
What I have done is made another transparent popup activity above the map activity which immediately calls onSearchRequested() during onCreate()
the thing is that when I type in something and click search, nothing happens. The search bar just clears itself but stays on screen as if prompting me to search for something again. I dont know what happens to this search query but I need it passed to my MapActivity.
I was considering doing startActivityforResult and passing a result back from the search popup activity, but I still have the dilemma of not knowing how to store the result and making search go away after clicking search
This class loads up a search box, thats all. It also has a transparent imageview in the space between the search box and keyboard. If a user clicks there, the activity is finished()
public class PseudoMapSearchActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pseudomapsearch);
onSearchRequested();
findViewById(R.id.blankness).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
});
final SearchManager searchManager =
(SearchManager) getSystemService(this.SEARCH_SERVICE);
searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
public void onCancel() {
searchManager.setOnCancelListener(null);
searchManager.stopSearch();
finish();
}
});
searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
public void onDismiss() {
searchManager.setOnCancelListener(null);
searchManager.stopSearch();
finish();
}
});
//searchManager.getSearchableInfo(getCallingActivity());
//searchManager.triggerSearch(query, launchActivity, appSearchData)
}
what searchManager function should I call to get the user typed and selected search query out of it
<activity android:name=".PseudoMapSearchActivity" android:theme="@style/Theme.Transparent" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.default_searchable"
android:value=".PseudoMapSearchActivity" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
Since the Pseudomapsearch popup activity won’t be doing the actual searching, and my activity with the map will be doing all the actual processing of this location data, should I then change the manifest somehow?
You could store your result from an
startActivityForResultin an Android SharedPreferences object. SharedPreferences are awesome, and can be gotten from anywhere in the application, or even globally. It is a good idea to have a class to store constants for SharedPreferences in, if you don’t have one.The documentation for SharedPreferences is great. Here is the link:
Hope this helps!
As for getting the data from the result, you need to use the method called
onActivityResult. Then use the appropriate request code.The documentation for the mentioned method can be found here: