How to add Search Dialog to an Android app - java

Here is my issue. I have a requirement to add a search dialog to an Android app. I have found the way to add a search view component, but not the search dialog. I know from the Android Developers docs that I am supposed to use onSearchRequested() to make it appear, but I don't quite understand what that means. Is the search dialog supposed to be tied to my own UI component that will invoke this method or am I missing something? I haven't managed to read all the docs on searching, but I was hoping someone may point me where I missed something important.
I am not well versed in Android development, only a few small projects. I am more of a Flutter dev when creating a mobile app, but I don't have the option this time around.
Below is the screenshot of what the Android Developers docs show as search dialog and the comparison to search view.

Based on the documentation, the steps for invoking a Search Dialog are:
create an Xml file (which you already did for search widget)
Declaring a searchable activity: create an actiivty and notify the Manifest that it gets the search results (you did that too)
3. At the Manifest, decalre some other activity (MainActivity for examlpe) to be able to invoke the search dialog. Add this line inside <activity> tag:
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
(android:value is the name of the Activity that gets the searcg results, which you defined at step 2)
4. At that Activity, create a search button etc and invoke the Serach Dialog like this:
onSearchRequested();
Very simple actually :)
The search words stored in intent.getStringExtra(SearchManager.QUERY) as a String, you get it at onCreate() of SearchableActivity class. From this point you should handle the search query and results logic...

Related

How to create custom map with customized markers in android studio XML

I have an app that has two activities, main_activity and second_activity. This app allow the user to book the entire house from a map.
From the first activity the user press the button and the second activity open.
Now I would like to implement on the second activity a customized map with customized markers. That looks like this, but I have no idea how to realize it, I have found a pic on google of what similar of what I would like to implement.
Could someone help me and explain me how I could reach this result?

Android - Perform an action with voice command

Searched through the internet and couldn't find a god example of achieving the following. There is a Launcher activity. User will be navigated to the launcher activity first and inside that activity , when the user says a certain word like "Start" or something like that the app should navigate the user to another activity. I've gone through a set of tutorials , and I've seen some similar questions at SO but none of them make sense to me. What will be the best approach to achieve this ?
Basically what you have to do is
build a framework/module to handle Speech Input (speech-2-text)
Depending on Input by user, perform an action

Android Development, Google Tutorial

I am following the Google tutorial for building your first android application. I got to the point where I needed to implement the actionbar actions with the functions openSearch() and openSettings().
I implemented all of this in the MainActivity.java file.
My question is this:
In the example app you can type a message and then send it and it displays it in a second activity. In the second activity, the top action bar changes and does not display my Search icon or perform the action when the settings button is clicked. In order to have these icons displayed in the action bar for this activity as well, do I need to add those methods and update onOptionsItemSelected method in DisplayMessageActivity.java as well as in MainActivity.java? Is this the only way to carry the action bar icons/actions over? To retype the same methods in each activity that you want them in? Or is there a better way to do it?
My other somewhat related curiosity is this. The method openSettings() is called when I click the 3 vertical dots and then settings. These 3 vertical dots show up on every activity, and settings is always in the list. However clicking settings obviously doesn't perform the call to openSettings() when in the DisplayMessageActivity and not MainActivity. How is it that settings and the vertical dots are carried over?
Second to last, how can I add other selections to the drop down list from the options/vertical dots in the action bar? Settings is always there although it responds differently in each activity which was my first question. But I would like to add certain things to the options menu that are on all activities, and some things that are unique to some activities. I assume there must be a better way than repeating switch statements and methods in every Activity.java file.
And finally, what is the best practice to implement an action bar over multiple activities?
Obviously different activities will often have different icons/actions in the action bar, however some things like the 3 vertical dots(options) and settings within that would obviously be acceptable to have in every Activity, while it would be nice to add other things to the options list I don't see why settings should ever change across activities. Yet as I stated before the method is not called in DisplayMessageActivity unless I repeat the code in DisplayMessageActivity.java that I had added to MainActivity.java. I'm confused as to where I can add these so that they are displayed on all activities without repeating code. And I'm confused as to how the actionbar's options/vertical dots are carried over to all activities while others require the repeating of code in each activities' java file that I want them to show up in.
I know this was a bit of a long winded quesiton, I will clarify if necessary. I'm just a bit confused. I was able to make it through the tutorial fine as I have a decent understanding of java. However google's guide isn't written that well and the Android environment is very confusing to a beginner.
I do understand how things work to a degree, I just want to ensure that I'm actually doing it in a way that when my app grows in complexity it won't be a mess of unnecessarily repeated statements and methods.
Thanks in advance for any assistance and tips.
In order to have these icons displayed in the action bar for this activity as well, do I need to add those methods and update onOptionsItemSelected method in DisplayMessageActivity.java as well as in MainActivity.java? Is this the only way to carry the action bar icons/actions over? To retype the same methods in each activity that you want them in? Or is there a better way to do it?
That is certainly one solution, but as you obviously know, it's not a very good one. There are at least two alternative solutions:
Create a MenuActivity class which implements all the logic for common menu items and then extend this class from all of your activities, rather than extending the standard Activity class.
Use fragments to implement your UI. Fragments are similar to activities in that they create UI elements from an XML layout. One difference is that they live inside a "host activity". In this particular case, the host activity will provide the common menu functionality and each fragment can customize it further depending on your needs.
How is it that settings and the vertical dots are carried over?
Most likely your DisplayMessageActivity overrides onCreateOptionsMenu() and inflates a menu XML layout which was created by Android Studio (or Eclipse?) when you created the activity class.

How to avoid titlebar of activity loading before actual activity loads and make it load with the activity load using java code?

.
I am doing reverse-engineering of applications.While reverse-engineering an app i needed to change the titles of each activities in an app that i got .I have a problem regarding activity titlebar.
Actually the developers of this app have set many of the titles from androidManifest.xml file using
<activity android:name="com.example.dmo.MainActivity" android:label="first"></Activity>
I changed the title of each activity by putting setTitle(" say abc"); in onCreate() of each activity and title is successfully changed, But problem is that while loading activity it shows the titlebar with the title from androidManifest.xml file i.e. android:label="first".
This title appears for some miliseconds (time increases if activity takes more tome to load), and then when my activity loads completely, title changes to the text i passed in setTitle() in onCreate().
This is somewhat similar to my problem.
I am not able to find solution since i have a strict restrictions that i can not make changes in any of the .xml fiels in an applicaion. I only allowed to change the java code and add some new java code if necessary.
I searched a lot but all solutions i found suggested changes in xml files; and some other solutions those suggested using code did not worked.
So is there any solution that does not require manual hard code xml changes directly. Changing xml using code is acceptable but not hard code changes like editing their original manifest file to :`<activity android:name="com.example.dmo.MainActivity" android:label="say abc"></Activity>`
Any AspectJ solution is also acceptable(i.e. some pointcut to some method that can do the work for me), if someone knows for the same.
I also want to know that, which class or api is responsible to load title bar before activity loads? ,so that if possible i can make changes in that .
Any help would be very appreciable . .Thank u in advance . .
Then the answer is you can't. This is the Application theme that is shown and it can be changed only in manifest. The screen you see is the Activity screen in state when the Application is not yet loaded and before any code in Activity onCrete() is executed.
Did you try apktool? You should be able to get editable manifest using it.

Start android program with settings

When my program start I would like to do some settings before is really starting. Forexample choose the user, check the updates and so on. After these settings I would like to start the main program with the appropriate.
Which is the best way to do this?
You can run an AyncTask, or multiple if you need one for each check, in your onCreate() and show a ProgressDialog while the data is being fetched then cancel it in onPostExecute() and move on to the rest of the MainActivity depending on the data that is downloaded. If you need help getting started with AsyncTask you can see this SO answer on the basic structure.
If you use a ProgressDialog then the app will still start but the users will see something and know that data is loading so they won't feel like it is freezing or taking too long to load (or at least they will know why it isn't loaded right away).
AsyncTask Docs
Edit after comment
For what you said you want in your comment you can do this easily with an Activity that has a Dialog Theme. This will give you the functionality you need (a couple Buttons and store the values) but it will look like a little popup. You can't use an actual Dialog as they need an Activity, the same with any menus, AFAIK. Just create your Activity and make it the launcher and main using the Intent-filters then also add the following line to that Activity's tag in the manifest
android:theme="#android:style/Theme.Dialog"
This approach should give you what you need
There are numerous ways to do that.
First - your app is doing some heavy stuff and this may be freezing user interface. In that version do:
1. Create and activity on what you will override onCreate method and set some content with a spinner - so something will be alive and user will see that something is being done.
2. after you will compute all the things that your app need and may I suggest write it to some global variables override onStart method in what change layout to what suit you and give a user a great UI!
Second - you app is not heavy lifting here just throw everything into override of onStart method.
Handy material here for educating:

Categories

Resources