android-training | 【Android Practice Manual】 | Android library
kandi X-RAY | android-training Summary
kandi X-RAY | android-training Summary
【Android Practice Manual】
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Finds the best method .
- Combine two arrays .
- Injects the patches .
- Generate resources .
- of the getValue method
- Sets the activity to be saved .
- Initialize the api .
- Init API 2 .
- Display a toast .
- Initialize the static map .
android-training Key Features
android-training Examples and Code Snippets
Community Discussions
Trending Discussions on android-training
QUESTION
What do I do if I want to hide "CHANGE TEXT" button AFTER it is tapped? From Android Kotlin Fundamentals: Add user interactivity
- Hide the DONE button by setting the
visibility
property toView.GONE
. You already have the button's reference as the function's input parameter,view
.
view.visibility = View.GONE
I try to follow that and the "CHANGE TEXT" button disappears before I tap the "CHANGE TEXT" button which is not what I want.
...ANSWER
Answered 2021-May-17 at 16:11You've just misplaced your changeText.visibility = View.GONE
it should be inside changeText.setOnClickListener
So your code would look like this:
QUESTION
My Settings: minSdkVersion 19 && compileSdkVersion 30
I tried below code. I expected the button's background to be colored as colorAccent
, but it was colored as colorPrimary
. When I change colorPrimary
value to another color, the button's background color changes accordingly.
This is contrary to what I learned. (Button's background should be colored by colorAccent
when style is "@style/Widget.AppCompat.Button.Colored"). I encountered this problem while following the Google Android fundamental tutorial (https://developer.android.com/codelabs/kotlin-android-training-interactivity/index.html#4).
I am getting confused, please help.
...ANSWER
Answered 2021-Apr-02 at 04:55I noticed that too button color set default as primary instead of Accent color but You can fix it by setting android:backgroundTint attribute of button instead of style-
QUESTION
I am trying to understand codelab 6.2 Coroutines and Room in Android Kotlin Fundamentals. Class SleepTrackerViewModel
includes (with comments added by me):
ANSWER
Answered 2021-Mar-08 at 21:04One of the reasons is that the nightId
in the SleepNight
data class is auto generated by SQL.
If the code would do tonight.value = newNight
then the nightId
wouldn't be the same than the one in the database. That would cause the update
call in onStopTracking
to end (update
) the wrong night.
Note too that the method getTonightFromDatabase
is called from a later version of SleepNightViewModel
:
QUESTION
I'm following the Android Code Lab for Espresso testing
It is outdated because it uses ActivityTestRule
instead of the recommended ActivityScenarioRule
Outdated Code Snippets
The rule
...ANSWER
Answered 2021-Feb-26 at 12:01I found the solution. The key is to get the context using InstrumentationRegistry.getInstrumentation().getTargetContext()
Create a helper function to retrieve the string array resource values
QUESTION
I worked myself thru the AndroidFundamtentals Tutorial 09.2 (App Settings) but I couldn't find a working solution for my problem.
I want to change the style (backgroundcolor) of the Settings-Fragment in my app.
That's what I have coded in the styles.xml so far:
...ANSWER
Answered 2021-Feb-22 at 17:23I just found the solution / mistake.
The parent of the style AppThemeWithActionBar
is wrong.
It changes the background to light.
Change the title of the style like this:
QUESTION
I am following the codelab https://developer.android.com/codelabs/kotlin-android-training-add-navigation/index.html#9, and I use the following code to wire up the drawer:
...ANSWER
Answered 2021-Jan-24 at 23:24I think if you add the layout in your navdrawer_menu.xml file the hamburger icon will remain
QUESTION
Except being the first Activity upon the Start of the Application, is there anything else special about main activity? From:https://developer.android.com/codelabs/android-training-create-an-activity#0
An app usually consists of multiple screens that are loosely bound to each other. Each screen is an activity. Typically, one activity in an app is specified as the "main" activity (MainActivity.java), which is presented to the user when the app is launched. The main activity can then start other activities to perform different actions.
From the quote above it seems to me that we have following hierarchy:
but then further is said:
Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack"). When a new activity starts, that new activity is pushed onto the back stack and takes user focus. The back stack follows basic "last in, first out" stack logic. When the user is done with the current activity and presses the Back button, that activity is popped from the stack and destroyed, and the previous activity resumes.
Does this also apply to the "MainActivity"
? If the "MainActivity"
is destroyed does that cause the App to crash i.e does the lifecycle of the MainActivity
in any way differs from the lifecycle of any other activity? Is the MainActivity the last activity that is being stopped when the App is exited?
Why do I need this:
I would like to free some resources when the App is exited (in the onStop()
Method (because post Honeycomb it is guaranteed that onStop
will be called)), especially ExecutorServices
, I've read here that even though App is exited there is no guarantee that an ExecutorService
will be stopped and will make JVM continue working/running, even though App is closed/killed and will continue to use system resources.
ANSWER
Answered 2020-Dec-24 at 12:17Main Activity
is the entry point for your app when user presses the icon for cold launch. You make any of your Activity a main activity in AndroidManifest.xml file via Intent Filter. Intent Filter tells the system which activity is main.
Although main activity is considered first entry point typically, but keep in mind, Main Activity is not always the first activity to be launched, for example there are various intent filters that can be assigned to your other Activity and that activity can be opened directly following the related action. Please read about the Intent-Filter here.
For example, your app is gallery app, typical first screen would be album list. from where you can view individual photo in PhotoActivity. This PhotoActivity can be opened directly via intent from outside apps to view a certain photo without needing to launch the main activity. (Check out google Photos app)
Regarding ExecutorServices or other services lifecycle, few options here:
- implement a ownership machanism, ie the activity that starts the service is responsible for closing the service
- You can monitor your app's activity stack and kill the service when your Activity stack is empty.
- Leverage Application class lifecycle to monitor things.
- Reasonable discussion here https://stackoverflow.com/a/5862048/593709
QUESTION
I have a simple setup of 2 fragments: ConversationFragment
and DetailsFragment
I am using Room
with Paging 3 library
and to populate the ConversationFragment
I am using a PagingLiveData
implementation together with a AndroidViewModel
belonging to the ConversationFragment
.
I am not using the Navigation Components
here, just a common fragment navigation as per Android documentation.
From that fragment I can open the DetailsFragment
and then return back to the fragment again. Everything is working well, until I open said fragment and return, then the observer that was tied in the ConversationFragment
is lost since that fragment is being destroyed when opening the DetailsFragment
.
So far this is not a big issue, I can restart the observer again and it does work when I do that.
However, when I attach the observer again the entire list reflows, this causes the items in the RecyclerView
to go wild, the position the list was on is lost and the scrollbar changes sizes which confirms pages are being loaded/reloaded.
I could withstand the weird behavior to a degree, but to have the position lost on top of that is not acceptable.
I looked into caching the results in the view model, but the examples I could find in the available documentation are basic and do not show how the same could be achieved using a LiveData<...>
object.
Currently this is what I have:
ConversationFragment
ANSWER
Answered 2020-Dec-11 at 10:18There's quite a lot to unpack here but my best guess would be your getList
method in ConversationViewModel
. You're on the right track with using ViewModels and LiveData to persist data across navigation but here you're recreating the LiveData every time this method is called, meaning when you resume ConversationFragment
and onViewCreated
is called, it creates a new Pager which fetches new data.
The solution would be to create the pager when ConversationViewModel
is first created and then accessing the LiveData object itself, rather than the method. You can see this in the Codelab example, they assign the LiveData in the constructor and simply return the already created LiveData in the getAllWords()
method.
I'm using this as an example, change ConversationViewModel
to something like this and change it to use your config and repository.
QUESTION
I used this CodeLabs tutorial to learn how to make an HTTP request from the Google Books API https://codelabs.developers.google.com/codelabs/kotlin-android-training-internet-data/#4
Right now, I'm trying to access a nested JSON object that the Google Books API spits out I.e
...ANSWER
Answered 2020-Oct-21 at 04:02I found out the reason why I was not getting any response. In my UpdateFragment, I'm doing this:
QUESTION
I have just started my first Kotlin app, and I'm aiming to learn the best practices for that language along the way (and end up with a working app of course :) ). I've come across a problem I find myself struggling with for some time: What should be the flow of an onClick event?
At first, I used the strait forward way of setting the onClick in my fragment like so: binding.image_profile_picture.setOnClickListener { onChangePhoto() }
.
I went over some of the kotlin training codelabs and changed my code accordingly. One thing I understood is that it is recommended to handle events in the ViewModel and not in the fragment (codelab#3), so now my onClicks are set in the layout xml like so: android:onClick="@{() -> profileViewModel.onChangePhoto()}"
.
The problem with that is all of my events actually need a context as they start with some kind of dialog (like the image picker). I found this article recommending to solve this problem using an event wrapper. I read the discussion on it's implementation's Github page and decided to give it a shot (also I'm not sure I like this unnecessary ViewModel-Fragment ping-pong). I implemented aminography's OneTimeEvent
and now my ViewModel looks like this:
ANSWER
Answered 2020-Oct-11 at 15:33First, using private backing fields can be very annoying. I would recommend using an interface
instead:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install android-training
You can use android-training like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the android-training component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page