How-to articles, tricks, and solutions about ANDROID

How to launch an Activity from another Application in Android

To launch an activity from another application in Android, you can use an Intent with the FLAG_ACTIVITY_NEW_TASK flag set.

How to pass an object from one activity to another on Android

There are several ways you can pass an object from one activity to another on Android:

How to print to the console in Android Studio?

To print to the console in Android Studio, you can use the Log class from the android.util package.

How to set selected item of Spinner by value, not by position?

To set the selected item of a Spinner by value (not by position) in Android, you can use the setSelection() method of the Spinner class and pass it the index of the item that you want to select.

Read/Write String from/to a File in Android

To read and write a string from and to a file in Android, you can use the FileInputStream and FileOutputStream classes along with the InputStreamReader and OutputStreamWriter classes.

RecyclerView onClick

To handle clicks on items in a RecyclerView, you can set an OnClickListener on the View that represents each item in the RecyclerView.

Sending Email in Android using JavaMail API without using the default/built-in app

To send an email in Android using the JavaMail API without using the default/built-in app, you can use the following steps:

Set ImageView width and height programmatically?

To set the width and height of an ImageView programmatically, you can use the setLayoutParams() method and pass it a LayoutParams object.

Unfortunately MyApp has stopped. How can I solve this?

If you are seeing the error "Unfortunately, MyApp has stopped," it means that your Android app has crashed. This can be caused by a number of factors, including:

Using context in a fragment

To use context in a fragment, you will need to provide enough information within the fragment itself for the reader to understand the context.

Why doesn't RecyclerView have onItemClickListener()?

RecyclerView does not have an onItemClickListener() method because it is not directly responsible for displaying a list of items.

1 2