I'm using a ContentProvider for search suggestions but I have a problem for handling a suggestion click: I explain the search works good but when I click in suggestion I go to the search activity but the re isn't anything, so how can I handle a click suggestion?
Your XML\searchable.xml (or equivalent) should include
android:searchSuggestIntentAction = android.intent.action.VIEW
otherwise your intent won't be called.
http://developer.android.com/guide/topics/search/searchable-config.html defines this field as:
The default intent action to be used when a user clicks on a custom
search suggestion (such as "android.intent.action.VIEW"). If this is
not overridden by the selected suggestion (via the
SUGGEST_COLUMN_INTENT_ACTION column), this value is placed in the
action field of the Intent when the user clicks a suggestion.
Related
I want to add search history to my SearchView. I found this question. It is rather useful but it looks like I can't handle it this way. First of all I use only fragments in my app while it looks like the solution above requires to create new activity for making search (well maybe I can reuse the same activity using some Intent flags). Also I can't provide search hint bia string resources.
I have fragment with SearchView in actionbar. When user enters search query I just perform web request and display results in the same fragment. I only need to add search history functionality to it. Can this be done completly programmatically?
I'm creating an app where I display a list of pending challenges. When the user clicks on a challenge, he can accept it or ignore it.
Here's what I want to do and I don't know how :
if the user accepts or ignore the challenge, call this.finished and remove the challenge from the list
if the back button is pressed, do nothing, the challenge is still visible
In short, if the user really responds to the challenge I don't want it to be displayed in the list, but if he doesn't choose any option and press the back button, he didn't choses one of the two actions so I want that challenge to still be visible in the list.
I don't think it's possible to detect what button I've pressed when i go back to my main activity. I've thought about using global variables, but I don't want to misuse them either.
Just to be clear, I'm not asking how deleting a list item. But when to know deleting one depending of the actions of another activity.
Give your second activity the index you want to remove as a parameter inside the intent and let it finish by returning the index again as an intent extra (by using setresult(Intent i) and then calling finish) inside your first activity catch the result from your second activity by overwriting onActivityResult (http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent))
see 3.3. Retrieving result data from a sub-activity in http://www.vogella.com/tutorials/AndroidIntent/article.html for a detailed howTo
I'm new to android development, and have set myself the task of creating a contact management application - just for the purpose of improving my skills.
The user has all the usual contact editing options available to them - find contact, new contact, edit contact, delete contact, etc. Each of these works in their own right - 'find contact' will 'select' the appropriate contact (store their ID in a public variable). If you press 'edit' or 'delete' whilst a contact is 'selected' then those functions work as they should.
But what happens when the user tries to press 'edit' or 'delete' when there is no contact selected? The simple solution would be to display the message 'please select a contact', but that is bad design. If the app needs user input, then they should be re-directed to the necessary activity to select a contact.
So when the user clicks the 'Edit' button, I wrote this very small snippet of code:
public void findContact(View view)
{
Intent intent = new Intent(this, FindContactActivity.class);
startActivityForResult(intent, 1);
}
public void editContact(View view)
{
if (Db.contact == null)
findContact(null);
else {
// navigate to edit activity
}
}
In this case, 'contact' is an object of type contact, which stores contact related information in it's own class. Db is a class that contains my database access functions - it seemed like a good spot to store a public variable that would need to be accessible from anywhere.
Now the code above obviously works fine. If a contact is selected, great - we go to the edit screen. If not, we go to the find-contact screen. But the problem is what happens once the user has selected a contact? It doesn't take them back to the edit screen again.
My ideal flow would be, in pseudo-code:
editContact()
{
if (contact is selected)
editContact();
else
{
findContact();
// once found, go to edit contact screen
editContact();
}
}
Bearing in mind I am brand new to android development, I was wondering if anyone could give me some pointers on creating the 'flow' of the application, as described above.
If I understand your problem there could be several ways to do it. I would probably simply disable the "Edit" Button if they haven't selected a contact yet because they shouldn't be able to try and edit if nothing is selected. However, if this doesn't work for you then you could pass a flag with your Intent. One thing I do sometimes is to pass a "source" flag.
After clicking edit and no contact is selected
Intent i = new Intent(Edit.this, FindContact.class);
i.putExtra("source", "edit");
startActivity(i);
then in your find contact get the extra
Intent intent = getIntent();
if ("edit".equals(intent.getStringExtra("source");
{
// create intent for EditScreen
You also could simply pass a boolean value this way with key "edit" and check if that is true. If so, then go to EditScreen if not go wherever you need to. I hope this helps. Let me know if I misunderstand.
You also will find different Intent.FLAGS very valuable
Actually android has a philosophy around the "flow" of activities which is covered here.
Since you are a new android developer it's mandatory to understand how activities are working.
By the info in your question it seems that you are not following android guidelines which is not necessarily a bad thing but you must have valid reasons not to. So by the programmatic view of your question I suggest that you disable the edit and delete buttons when a contact is not selected or if you prefer, to restrict user's choices based on the data selected or displayed.
However you are asking about the "flow" so my advice here is to study more about activities and how the back stack is working and look at the sdk examples. In most of the applications that a user can make some actions based on data selected those actions are presented to the user after a longclick on a record. In your case a pseudo flow would be something like this:
Find Activity --> Results --> Click on a Result --> Choices List (Edit, Delete e.t.c) --> Edit or Delete Activity (after edits goes back to Results)
Now about "creating a less linear flow of activities" IMO is a little too generic. You can control the flow of your activities as you want by using either the techniques in the design (look my link on top) or by code by using for example the finish method which removes the activity from the back stack.
Hope this helps...
I have a search feature with a list view. When the user click on search and filters the result the activity is loaded from the beginning. So here is the flow.
User opens my application (Gets the whole list ot items) -> Search1 (Filtered search) -> Search2 (Filtered result 2) -> Search3 (Filtered result 3). Now when the user clicks back he goes to Search 2 -> then back to result 1 -> then back to the mail list.
This is how is my application working now. I want this to change as when users is on any search result I want him to go back to main list without going back to any search results.
Basically I dont want android system to track the search results so that when user clicks back, he should directly go to the main list.
How do I do this. Please advice if you have any alternative for this. Thank you for your advice and time. Thank you.
You should set your search activity to be android:launchMode="singleTop" in your manifest, that way there's a single search activity and you're only responding to search intents within it. This is actually the "ideal" behavior according to the docs.
When you are done with the search results you could finish that activity. You might even be able to use finishOnTaskLaunch to achieve the same thing and it is probably more desirable too.
My application shall work the following way:
Activity #1 contains a text field (EditText) and a button.
If the user clicks the button a search dialog is opened via onSearchRequested().
This calls the searchable activity #2 which extends ListActivity. It provides a list of items via setListAdapter().
If the user clicks on a list item activity #2 shall pass the selected item's text back to activity #1 and display it in the text field.
Bullets #1-3 are clear and working. However I don't have any idea how to implement #4. I know about the possibility to use intents but it doesn't work if I use an intent after onSearchRequested().
Thanks,
Robert
The following solution is working fine for me:
http://blog.dpdearing.com/2011/05/getting-android-to-call-onactivityresult-after-onsearchrequested/
I would simply send an intent with your selected item as extra (putExtra) to your activity#1 (since the search dialog is between activity#1 and activity#2, you can not use startActivityForResult to post back the result to activity#1)
If the search dialog is in activity#1, then you can use startActivityOnResult (thanks dmon)
Simple, quick fix: store the data statically and do a check to retrieve it in Activity #1's onResume().