Azhar

Azhar

451 Articles Published

Articles by Azhar

451 articles

How to detect device is Android phone or Android tablet?

Azhar
Azhar
Updated on 07-Feb-2025 3K+ Views

In this article we will see, how we can detect the device is an Android phone or Android tablet. Here are the following steps for it.Detecting device is Android phone or Android tablet The following are the steps tp detect device is Android phone or Android tablet:Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.   Step 3 − Add the following code to src/MainActivity.java import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.os.Bundle; import ...

Read More

How to use SharedPreferences on Android to store, read and edit values using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 369 Views

This example demonstrates how to use SharedPreferences on Android to store, read and edit values using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                             Step 3 − Add the following code to src/MainActivity.ktimport android.content.SharedPreferences import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var editTextName: EditText    private lateinit ...

Read More

How to pass data between Activities on an Android application using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 507 Views

This example demonstrates how to pass data between Activities on an Android application using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val myRequestCode = 1    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main) ...

Read More

How to call OnDestroy Activity in an Android App using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 1K+ Views

This example demonstrates how to call OnDestroy Activity in an Android App using Kotlin?Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val myTag = "Destroy"    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"   ...

Read More

How to get the current date and time from the internet in Android using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 753 Views

This example demonstrates how to get the current date and time from the internet in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.text.SimpleDateFormat import java.util.* class MainActivity : AppCompatActivity() {    lateinit var calendar: Calendar    lateinit var simpleDateFormat: SimpleDateFormat    lateinit var date: String    lateinit ...

Read More

How to write files to the assets folder in android using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 1K+ Views

This example demonstrates how to write files to the assets folder in android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.io.IOException import java.io.InputStream class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState) ...

Read More

Where and how to use static variables in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 586 Views

This example demonstrates how to use static variables in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val tag = "I'm a Static Variable"    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ...

Read More

How do I specify different layouts for portrait and landscape orientations in Android?

Azhar
Azhar
Updated on 30-Nov-2020 2K+ Views

This example demonstrates how do I specify different layouts for portrait and landscape orientations in androidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 – Create a layout file by right-clicking on the resources, name the file, from the ‘Available qualifiers, select Orientation.Click >> option.Select Landscape from UI mode.Add the following code in the res/layout/land/activity_main.xml         Step 4 − Add the following code to ...

Read More

How to set maximum date in datepicker dialog in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 2K+ Views

This example demonstrates how to set maximum date in datepicker dialog in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.app.DatePickerDialog import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.text.SimpleDateFormat import java.util.* class MainActivity : AppCompatActivity() {    private var year = 0    private var month = 0    private var day = 0    lateinit var textView: ...

Read More

How to change Screen Orientation programmatically using a Button in Android Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 2K+ Views

This example demonstrates how to change Screen Orientation programmatically using a Button in Android Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.content.pm.ActivityInfo import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.Toast class MainActivity : AppCompatActivity() {    lateinit var buttonLandscape: Button    lateinit var buttonPortrait: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)     ...

Read More
Showing 1–10 of 451 articles
« Prev 1 2 3 4 5 46 Next »
Advertisements