First some background.
In my edit item activity I have added search functionality to change of one of the item's data fields. (Its manufacturer and make). Since the user can select from quite a large amount of items, we have decided to use search with suggestions to change the manufacturer/model.
Using the normal Android search, from the edit activity I can override the onSearchRequested() method and add the current item's ID as part of the extra data. The actual updating of the data item, is done in the search activity. (I know, not the best idea, but my edit activity doesn't know what the user did in the search activity.)
This works fine for a simple search, but I can't seem to find a place to inject this context data (the item's id) for Search Suggestions.
I have read through the android docs and the closest I have come across is SUGGEST_COLUMN_INTENT_EXTRA_DATA column for the resultant row in my suggestion, but since my search content provider also doesn't have any context of what item I am editing, it doesn't seem like it will solve my problem. The Intent is still launched from the suggestion by the Android system, and I can't seem to get the required context info added to it.
Is this even possible given that search suggestions seems to be geared towards context-less global searches i.e. Android's quick search?
For completeness sake: we are targeting platforms less than Android 3.0, so the functionality of SearchView is not available.
Good news: the Intent that the suggestions launch directly is the same one that the activity sets up in the call to 'onSearchRequested()'. Any context info can be set there. Can anyone find a reference to this in the docs?
Related
I would like to change the entire locate app.
context.resource.configuration.locale = Locale("ar")
My app is single activity one.
I pay attention that changing the locate inside the Context which I receive from the Fragment handle the situation in all my Fragments, unlike changing it from the Activity which I receive no result...
My question is if somebody have a clue why is this happen? or how can I change the app locale in the entire app?
I read some posts and non of them was good enough.
The guide from Android developers is rather ambiguous.
The default implementation of onSaveInstanceState() saves information about the state of the activity’s view hierarchy, such as the text in an EditText widget or the scroll position of a ListView widget.
These get stored as far as I know:
the Intent that started your activity (found out through testing)
properties of the objects in the Activity's view graph if they have been given an Id, presumably
Fragments that are not in the back stack and which have been set to retain their instance (Fragment#setRetainInstance(boolean))
However, in the API I have not found such contract being described and I am not sure whether this list is exhaustive either. I have not been able to find any documentation which clearly expresses what gets stored.
This is a possible duplicate to this question, however that question doesn't ask for sources or exhaustiveness and the answers there do not provide that. Are developers supposed to just look into the SDK in every single View, Activity, Fragment, AutofillManager etc. they use to see what gets saved and what doesn't? What are the guarantees?
Hi I have problem with planning implementation of specific search interface.
I am making navigation application where you can navigate from point to point.
For this I need two seachviews both with different searchable configuration, where I can define different custom intent action to recognize if user enter source or destination and react properly. I have already created suggestion logic because I am using one SearchView in other activity and already have different configuration there.
So my plan is creating an activity for result which will be in same time SearchActivity where I will setup two different SearchViews components where based on user input there will appear suggestions and after clicking them (first later second) the intent will be picked by CUSTOM1/2 ation intent in onNewIntent() as it will be "singleTop" activity and stored properly. Then i will process stored source&destination data and finish with proper response code to the source activity with extras based on processed data.
I don't know if I explained it properly. The main problem for me here is that I need to have two different SeachViews widgets. How to achieve this?
Eventually I can manage both SearchView suggestion results with default ACTION_VIEW and recognize them by sent data but I think the first plan is more clear.
PS I am planning to put them directly to the layout without appbar.
My goal:
Implementing search within an application.
How it should work:
I have multiple activities which have a SearchView within their Action Bar (or Toolbar as they now call it), and a dedicated Search activity. I want to be able to input text in the SearchView, receive suggestions while i am inputting text and when i send the search to launch the dedicated activity and do a proper listing of the results.
What i have done so far:
I have gone with the SearchView with ContentAdapter method as suggested here. I have managed to have the SearchView in every activity, when i press go on the keyboard i am taken to the dedicated Search activity and the query is displayed (going to implement the effective search later). So far so good.
The problem:
I have attempted to create a custom ContentProvider to provide some mock-up suggestions but i am unable to make it work. I define within it a custom String[], and then in the query method match my search with the elements in said string. The cursor is registered, and the query method fires when i am writing text but no results are displayed in the non-dedicated activities. In the dedicated Search activity i am shown an empty list-view and receive an "error changing cursor and caching columns" IllegalStateException
I am having trouble finding any information as everyone seems to use the ContentProvider with a local database. I however intend in the future to receive my information from a REST API in the query method and return the cursor using the received values (as in this example)
I would greatly appreciate any advice in this matter. As I am not sure what code to provide, I will provide it on request.
Fixed it...
The problem was that I was creating my MatrixCursor in onCreate.
The solution is to declare and instantiate the cursor in the query method.
Side note:
As it turns out, in the columns String[] that you pass to the MatrixCursor's constructor you need to specify the values using the SearchManager constants (ie SearchManager.SUGGEST_COLUMN_TEXT_1), otherwise the text will not be displayed within the suggestion view if you use the default view and adapter.
I hope this helps someone.
I have a question around ListActivities, put into an example for hopefully more clarity. ;)
My application has a TitleListActivity which shows the published titles of a particular author. This list might contain one or more titles depending on the author. When there is only one title in the list i want to immediately start the TitleViewActivity for the particular title rather than showing the boring list with one title. I assume pretty common thing, just havent found any explanation on it so far.
Easy approach would be to check before calling the TitleListActivity how many titles there are for this author and start the respective activity. As the TitleListActivity call can happen from different parts of the application I would like to centralize the logic which decides what Activity to call.
My question is what is the best practice to achieve this. Can this logic be added to the TitleListActivity in my example efficiently. All the history back button logic etc should work of course.
Any suggestion highly appreciated
Thanks
martin
I would probably make a Activity launcher class/controller with a static method for launching the TitleList or Title. Would be something like ActivityLauncher.lauchAuthorActivity(context, auther) and that function would decide on what activity to launch.
Better use Intent.putExtra() instead of static method or class.
You must have already been using something like a AuthorId to get respective author's Titles.
Just use 1 more attribute TitleCount
intent.putExtra("TitleCount", n);
check it in TitleListActivity, and if its 1 finish() TitleListActivity in the 1st line of onCreate and open the Title Page.
If you are getting all the data of Titles(including the Title count) in the TitleListActivity check the Array/ArrayList size which has these titles.