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
Related
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...
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?
I would like to show a notification and play a sound when the user taps onto that notification. It works somehow when I use an activity to play the sound, as I have written in my own answer to this question: How can I create a notification that plays an audio file when being tapped? (in this question and answer there is also the source code showing how I create the notification and how my PlaySoundActivity looks like.
Yet, I have realized, that while the sound is playing, the appearance of my main application changes and it will not be restored without closing the application.
I have created my application from the "Tabbed Activity" project template.
This is how it looks after being started:
And this is how it looks when I have tapped onto the sound notification (the sections are gone):
Can anyone explain why this happens? Is it a wrong approach to play sound using an activity? But it does not work here when I use a service, I hear nothing! How to solve that?
According to the Android developer reference, "almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)".
I had not done this. Therefore a new window was displayed, but there was no content.
The better solution for playing a sound is to use a PlaySoundService (service!!!) instead of an activity. It contains almost the same code as an activity would do, but the pending intent is created with PendingIntent.getService(...) instead of PendingIntent.getActivity(...). Using the wrong method does not result in an obvious error message, but the service won't work as expected.
Before people say this is a duplicate of "check if android is on first run", this question is to check if the activity itself (not the app in whole) is open for the first time.
I have different activities that run Material Tap Target Prompt, so a few pop-ups that explain the buttons and functions.
But I only want it to run for first time users.
Now I tried the following:
if (prefs.getBoolean("firstRun", true)) {
prefs.edit().putBoolean("firstRun",false).apply();
........Do the pop ups
}
But this will set it for the whole app and so when the user gets to the next screen it won't run because the boolean is set to false.
So I am trying to find a way to check if the activity itself is opened for the first time but I can't seem to find anything that would solve this issue.
I thought about using a variable then setting it to 1. But if the users restarts the app, it crashes etc then that var will be reset.
May other option is to create a row in a DB and then check if that is set to 1 or whatever depending on the activity.
But maybe there is an easier way?
Thank you
Why don't you just create preference keys for each Activity. Sample code added below:
if (prefs.getBoolean(MainActivity.class.getCanonicalName(), true)) {
prefs.edit().putBoolean(MainActivity.class.getCanonicalName(),false).apply();
........Do the pop-ups
}
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: