Found 1631 Articles for Android

How to check the amount of RAM to be used by an Android App?

Azhar
Updated on 21-Aug-2019 07:48:28

610 Views

This example demonstrates how do I check the amount of RAM to be used by an android app.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.app.ActivityManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       final TextView textView = findViewById(R.id.text); ... Read More

Communication between Activity and Service in Android?

Azhar
Updated on 21-Aug-2019 07:57:55

2K+ Views

This example demonstrates how do I communicate between Activity and Service 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.javaimport android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity implements View.OnClickListener {    Button buttonStart, buttonStop;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       ... Read More

How to ping external IP from java Android?

Azhar
Updated on 21-Aug-2019 07:50:28

3K+ Views

This example demonstrates how do I ping external IP from java 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.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; import java.io.IOException; public class MainActivity extends AppCompatActivity {    Boolean isConnected = false,    isWiFi = false,    isMobile = false;    @Override    protected void onCreate(Bundle savedInstanceState) {       ... Read More

How to use snackbar in Android?

Azhar
Updated on 01-Jul-2020 11:52:30

799 Views

This example demonstrates how do I use snackBar 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 – Open build.gradle(Module app) add the following dependancy -implementation 'com.android.support:design:28.0.0'Step 4 − Add the following code to src/MainActivity.javaimport android.graphics.Color; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ... Read More

How to register a BroadcastReceiver programmatically in Android?

Azhar
Updated on 01-Jul-2020 12:06:59

2K+ Views

This example demonstrates how do I register a BroadcastReceiver programtically 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.javaimport android.content.IntentFilter; import android.net.ConnectivityManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    ExampleBroadcastReceiver exampleBroadcastReceiver = new ExampleBroadcastReceiver();    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    }    protected void onStart(){     ... Read More

How to display toast messages from a thread in Android?

Azhar
Updated on 01-Jul-2020 08:20:43

898 Views

This example demonstrates how do I display toast messages from a thread 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.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    Toast toast;    Thread thread;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       toast = Toast.makeText(this, "This is a toast ... Read More

How to set the part of the Android TextView as clickable?

Azhar
Updated on 01-Jul-2020 08:21:17

2K+ Views

This example demonstrates how do I set the part of the Android textView as clickable.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.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

How to format date and time in android?

Azhar
Updated on 01-Jul-2020 08:23:14

2K+ Views

This example demonstrates how do I format date and time 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.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import java.text.SimpleDateFormat; import java.util.Calendar; public class MainActivity extends AppCompatActivity {    TextView textView;    String dateTime;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView = findViewById(R.id.textView); ... Read More

How to get screen DPI programmatically in Android?

Azhar
Updated on 01-Jul-2020 08:24:22

997 Views

This example demonstrates how do I get screen DPI programatically 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.javaimport android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    Button button;    TextView textview;    float value = 0;    DisplayMetrics displaymetrics;    Activity activity;    @Override    protected void ... Read More

How to customize a button to set text and color in Android?

Azhar
Updated on 01-Jul-2020 08:10:01

2K+ Views

This example demonstrates how do I customize a button to set text and color 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.javaimport android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; public class MainActivity extends AppCompatActivity {    Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       button = findViewById(R.id.customBtn); ... Read More

Advertisements