Posts

Showing posts with the label Kotlin

Volley in Android

Image
Overview Volley is a HTTP Library that is used in Android applications. It is used to make networking tasks easier and most importantly faster. With Volley all you have to do is add your request in a RequestQueue and you will get your response parsed and delivered in the form of Response Listener  if everything is fine or else Response Error Listener. Steps to follow Add the following dependency def volley_version = "1.2.1" implementation " com.android.volley:volley: $volley_version " Add Internet permission in AndroidManifest.xml file < uses-permission android :name ="android.permission.INTERNET" /> For a Simple String Request class MainActivity : AppCompatActivity () { companion object { const val SERVER_URL = "https://jsonplaceholder.typicode.com/posts/1" } private lateinit var requestQueue : RequestQueue override fun onCreate ( savedInstanceState: Bundle? ) { super .onCreate ( savedInstanceState ) ...

Twilio with Android in Kotlin

Image
Overview Twilio is third party service that can be used to receive calls, send SMS, chat, email, IVR and many other services. This service is paid. Add the following steps Add the required dependency in build.gradle (Module) file. implementation "com.squareup.okhttp3:okhttp:4.9.1" Create an XML File <? xml version ="1.0" encoding ="utf-8" ?> <androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" android :padding ="20dp" tools :context =".MainActivity" > <TextView android :id ="@+id/tvPhone" android :layout_width ="wrap_content" and...

Fragment in Android

Image
Overview Fragment is also called sub-activity. It is an application component which is dependent on Fragment. Following is the Fragment lifecycle. Activity with Fragment rotated Steps to follow Enable view binding in build.gradle (Module) file to use ActivityMainBinding. buildFeatures { viewBinding true } Create blank fragments inside an Android project. It will create a Java/Kotlin file and the associated xml file.  Extend the Java/Kotlin file with Fragment class. (When you create a new Fragment on Android Studio, the studio automatically creates basic boilerplate codes for you). class FragmentA : Fragment() { private lateinit var communicator : Communicator override fun onCreateView ( inflater : LayoutInflater , container : ViewGroup? , savedInstanceState : Bundle? ) : View? { communicator = activity as Communicator val view = inflater.inflate(R.layout. fragment_a , container , false ) view.btnSend.setOnClickListener { ...