Found 2041 Articles for Mobile Development

Android AsyncTask example and explanation

Chandu yadav
Updated on 25-Jun-2020 09:50:51

12K+ Views

Android AsyncTask going to do background operation on background thread and update on main thread. In android we cant directly touch background thread to main thread in android development. asynctask help us to make communication between background thread to main thread.Methods of AsyncTaskonPreExecute() − Before doing background operation we should show something on screen like progressbar or any animation to user. we can directly comminicate background operation using on doInBackground() but for the best practice, we should call all asyncTask methods .doInBackground(Params) − In this method we have to do background operation on background thread. Operations in this method should ... Read More

What is difference between gravity and layout_gravity on Android?

Ankith Reddy
Updated on 26-Jun-2020 05:48:05

960 Views

Android supports both gravity and layout_gravity. Gravity adjusts view position. Using gravity we can do alignment of view as shown below.In the above code Textview going to set in middle of parent layout.Properties of GravityCenter − it going to put view in center of parent layout.Right − it going to put view in right of parent layout.Left − it going to put view in left of parent layout.End − it going to put view in end position of parent layout.Start − it going to put view in start position of parent layout.Top − It going to put view in Top ... Read More

How to get the dimensions of a view in Android?

Arjun Thakur
Updated on 25-Jun-2020 09:55:03

5K+ Views

There are so many cases, we should create dynamic view rather than creating view in XML. In that scenario, we should need to get the dimensions of a view. So here is a simple solution to get the dimensions of a view in android.To get the height of any view use the following codeint width = view.getMeasuredHeight();To get the width of any view use the following codeint height = view.getMeasuredWidth();Before get the width and height, we should assign default measure for a view as shown belowview.measure(0, 0);In the above code view is like either textview ,editText, button ..etc. Here is ... Read More

How to display HTML in TextView in Android?

George John
Updated on 26-Jun-2020 05:51:31

5K+ Views

In Some situations, we should need to show HTML as text in android. Here is the simple solution to show HTML in TextView in android.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.javapackage com.example.andy.myapplication; import android.os.Bundle; import android.support.v4.text.HtmlCompat; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    String htmlText = "What is Android?" + "Android is an open source and Linux-based ... Read More

How to close or hide the virtual keyboard on Android?

Chandu yadav
Updated on 25-Jun-2020 10:17:36

4K+ Views

In Android there are some situations, we should close android default keyboard forcefully. For that this example is help for you.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 3Add the following code to src/MainActivity.javaimport android.app.ProgressDialog; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; public class MainActivity extends AppCompatActivity implements View.OnClickListener {    Handler mHandler;   ... Read More

How to check visibility of virtual keyboard on Android?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

797 Views

There are some situations, we should find keyboard is visible or not in particular activity. In this example we can check visibility of virtual keyboard on android.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.javaimport android.graphics.Rect; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.constraint.ConstraintLayout; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public ... Read More

How to access unique Android device ID?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

2K+ Views

If you want to check unique device id like IMEI number through programmatically we can do this by telephonic manger as shown below example −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.javaimport android.Manifest; import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import ... Read More

How to create a notification with NotificationCompat.Builder in Android?

George John
Updated on 26-Jun-2020 05:38:04

3K+ Views

Before getting into NotificationCompact.Builder, we should know what is a notification in android. Notification is just like as a message showing system on the action bar. just like missed call notification as shown belowThis example demonstrates how to integrate Android Notification.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.javapackage com.example.andy.myapplication; import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import ... Read More

How do I display an alert dialog on Android?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

3K+ Views

Before getting into alert dialog, we should know about what is alert dialog, Alert dialog is just like a pop-up where user can choose action by clicking "ok" or "cancel" button.Methods in Alert DialogsetView(View view) − It used to set custom view to alert dialogsetTitle(CharSequence title) − It is used to set title to alert dialogsetMessage(CharSequence message) − It is simple call as content in alert boxsetIcon(int resId) − it is used to set icon for alert boxsetButton(int whichButton,  CharSequence text,  Message msg) − It is used to set button for alert dialog as shown below example.getListView() − it is used to ... Read More

Handler in android ?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

11K+ Views

We cant touch background thread to main thread directly so handler is going to collect all events which are available in main thread in a queue and posses this queue to looper class.In android Handler is mainly used to update the main thread from background thread or other than main thread. There are two methods are in handler.Post() − it going to post message from background thread to main thread using looper.sendmessage() − if you want to organize what you have sent to ui (message from background thread) or ui functions. you should use sendMessage().This example demonstrate about how to ... Read More

Advertisements