Questions tagged [android]

Android is Google's mobile operating system, used for programming or developing digital devices (Smartphones, Tablets, Automobiles, TVs, Wear, Glass, IoT). For topics related to Android, use Android-specific tags such as android-intent, android-activity, android-adapter, etc. For questions other than development or programming but related to the Android framework, use this link: https://android.stackexchange.com.

Filter by
Sorted by
Tagged with
228 votes
3 answers
38k views

How to use ThreeTenABP in Android Project

I'm using Android Studio 2.1.2 and my Java setup is the following: >java -version > openjdk version "1.8.0_91" > OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~15.10....
  • 6,547
869 votes
23 answers
544k views

Unfortunately MyApp has stopped. How can I solve this?

I am developing an application, and everytime I run it, I get the message: Unfortunately, MyApp has stopped. What can I do to solve this? About this question - obviously inspired by What is a ...
  • 97.5k
2686 votes
66 answers
1.5m views

How can I fix 'android.os.NetworkOnMainThreadException'?

I got an error while running my Android project for RssReader. Code: URL url = new URL(urlToRssFeed); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory....
  • 29.1k
1519 votes
53 answers
1.2m views

How do I pass data between Activities in Android application?

I have a scenario where, after logging in through a login page, there will be a sign-out button on each activity. On clicking sign-out, I will be passing the session id of the signed in user to sign-...
320 votes
15 answers
135k views

When does SQLiteOpenHelper onCreate() / onUpgrade() run?

I have created my tables in my SQLiteOpenHelper onCreate() but receive SQLiteException: no such table or SQLiteException: no such column errors. Why? NOTE: (This is the amalgamated summary ...
182 votes
3 answers
569k views

How do I parse JSON in Android? [duplicate]

How do I parse a JSON feed in Android?
  • 6,447
1384 votes
44 answers
647k views

Strange OutOfMemory issue while loading an image to a Bitmap object

I have a ListView with a couple of image buttons on each row. When the user clicks the list row, it launches a new activity. I have had to build my own tabs because of an issue with the camera layout. ...
2065 votes
41 answers
575k views

How to lazy load images in ListView in Android

I am using a ListView to display some images and captions associated with those images. I am getting the images from the Internet. Is there a way to lazy load images so while the text displays, the UI ...
2849 votes
35 answers
894k views

How can I save an activity state using the save instance state?

I've been working on the Android SDK platform, and it is a little unclear how to save an application's state. So given this minor re-tooling of the 'Hello, Android' example: package com.android.hello; ...
  • 45.2k
57 votes
6 answers
44k views

How to return DataSnapshot value as a result of a method?

I don't have much experience with Java. I'm not sure if this question is stupid, but I need to get a user name from Firebase realtime database and return this name as a result of this method. So, I ...
  • 731
598 votes
30 answers
741k views

How to use SharedPreferences in Android to store, fetch and edit values [closed]

I want to store a time value and need to retrieve and edit it. How can I use SharedPreferences to do this?
190 votes
11 answers
116k views

Android permission doesn't work even if I have declared it

I'm trying to write code to send an SMS from an Android app, but when I try to send the SMS it sends me back the error: 09-17 18:37:29.974 12847-12847/**.**.****E/AndroidRuntime﹕ FATAL EXCEPTION: ...
1094 votes
14 answers
887k views

How to manage startActivityForResult on Android

In my activity, I'm calling a second activity from the main activity by startActivityForResult. In my second activity, there are some methods that finish this activity (maybe without a result), ...
  • 51.4k
698 votes
25 answers
470k views

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

I am trying to create a mail sending application in Android. If I use: Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); This will launch the built-in Android application; I'm ...
3041 votes
54 answers
1.2m views

Is there a unique Android device ID?

Do Android devices have a unique ID, and if so, what is a simple way to access it using Java?
  • 31k
31 votes
4 answers
8k views

Why does my function that calls an API or launches a coroutine return an empty or null value?

(Disclaimer: There are a ton of questions which arise from people asking about data being null/incorrect when using asynchronous operations through requests such as facebook,firebase, etc. My ...
711 votes
21 answers
1.1m views

AsyncTask Android example

I was reading about AsyncTask, and I tried the simple program below. But it does not seem to work. How can I make it work? public class AsyncTaskActivity extends Activity { Button btn; /** ...
  • 9,382
6303 votes
32 answers
1.5m views

What is the difference between px, dip, dp, and sp?

What is the difference between the units of measure px, dip, dp, and sp?
1047 votes
23 answers
585k views

How to create RecyclerView with multiple view types

From Create dynamic lists with RecyclerView: When we create a RecyclerView.Adapter we have to specify ViewHolder that will bind with the adapter. public class MyAdapter extends RecyclerView.Adapter<...
  • 13.1k
15 votes
1 answer
5k views

getContactsFromFirebase() method return an empty list

public List<String> getContactsFromFirebase(){ FirebaseDatabase.getInstance().getReference().child("Users") .addListenerForSingleValueEvent(new ValueEventListener() { ...
4282 votes
126 answers
1.8m views

How to close/hide the Android soft keyboard programmatically?

I have an EditText and a Button in my layout. After writing in the edit field and clicking on the Button, I want to hide the virtual keyboard when touching outside the keyboard. I assume that this is ...
1127 votes
108 answers
904k views

R cannot be resolved - Android error

I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it. The wizard created this code: package eu.mauriziopz.gps; import android.app.Activity; ...
30 votes
2 answers
12k views

How to return a DocumentSnapShot as a result of a method?

A custom object that takes a parameter of (DocumentSnapShot documentsnapShot). also is an inner object from Firebase that retrieves a snapshot and set the values to my custom model also have its ...
  • 305
1626 votes
37 answers
1.3m views

Android 8: Cleartext HTTP traffic not permitted

I had reports from users with Android 8 that my app (that uses back-end feed) does not show content. After investigation I found following Exception happening on Android 8: 08-29 12:03:11.246 11285-...
  • 16.5k
1240 votes
40 answers
293k views

Is quitting an application frowned upon?

Moving on in my attempt to learn Android, I just read the following: Question: Does the user have a choice to kill the application unless we put a menu option in to kill it? If no such option ...
1121 votes
16 answers
619k views

Download a file with Android, and showing the progress in a ProgressDialog

I am trying to write a simple application that gets updated. For this I need a simple function that can download a file and show the current progress in a ProgressDialog. I know how to do the ...
  • 19.1k
901 votes
27 answers
596k views

android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

The app is crashing when I'm trying to open a file. It works below Android Nougat, but on Android Nougat it crashes. It only crashes when I try to open a file from the SD card, not from the system ...
  • 12.1k
547 votes
26 answers
440k views

How to programmatically take a screenshot on Android?

How can I take a screenshot of a selected area of phone-screen not by any program but from code?
  • 6,261
333 votes
14 answers
596k views

Shared preferences for creating one time activity

I have three activities A, B and C where A and B are forms and after filling and saving the form data in database (SQLite). I am using intent from A to B and then B to C. What I want is that every ...
  • 3,455
671 votes
49 answers
783k views

RecyclerView onClick

Has anyone using RecyclerView found a way to set an onClickListener to items in the RecyclerView? I thought of setting a listener to each of the layouts for each item but that seems a little too much ...
  • 6,728
995 votes
15 answers
249k views

Ship an application with a database

If your application requires a database and it comes with built in data, what is the best way to ship that application? Should I: Precreate the SQLite database and include it in the .apk? Include the ...
237 votes
13 answers
417k views

Custom Adapter for List View

I want to create a custom adapter for my list view. Is there any article that can walk me through how to create one and also explain how it works?
  • 53.5k
154 votes
3 answers
84k views

How ListView's recycling mechanism works

So I have this problem I had before, and naturally I asked for help on here. Luksprog's answer was great because I had no idea about how ListView and GridView optimized itself with recycling Views. So ...
  • 10.5k
1951 votes
46 answers
1.2m views

How to get screen dimensions as pixels in Android

I created some custom elements, and I want to programmatically place them to the upper right corner (n pixels from the top edge and m pixels from the right edge). Therefore I need to get the screen ...
  • 65.7k
555 votes
32 answers
580k views

How to handle notification when app in background in Firebase

Here is my manifest: <service android:name=".fcm.PshycoFirebaseMessagingServices"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT&...
  • 6,408
336 votes
5 answers
224k views

How to use an existing database with an Android application [duplicate]

I have already created an SQLite database. I want to use this database file with my Android project. I want to bundle this database with my application. Instead of creating a new database, how can ...
187 votes
12 answers
343k views

Storage permission error in Marshmallow

In Lollipop, the download functionality works fine in my app, but when I upgraded to Marshmallow, my app crashes and gives this error when I try to download from the internet into the SD card: ...
  • 7,867
885 votes
35 answers
840k views

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

I am trying to work on sending an object of my customer class from one Activity and displaying it in another Activity. The code for the customer class: public class Customer { private String ...
  • 17.1k
856 votes
28 answers
362k views

What is the simplest and most robust way to get the user's current location on Android?

The LocationManager API on Android seems like it's a bit of a pain to use for an application that only needs an occasional and rough approximation of the user's location. The app I'm working on isn't ...
  • 99.4k
319 votes
38 answers
514k views

recyclerview No adapter attached; skipping layout

Just implemented RecyclerView in my code, replacing ListView. Everything works fine. The data is displayed. But error messages are being logged: 15:25:53.476 E/RecyclerView: No adapter attached; ...
  • 3,393
359 votes
23 answers
591k views

Send data from activity to fragment in Android

I have two classes. First is activity, second is a fragment where I have some EditText. In activity I have a subclass with async-task and in method doInBackground I get some result, which I save to ...
  • 7,041
121 votes
13 answers
23k views

NullPointerException accessing views in onCreate()

This is a canonical question for a problem frequently posted on StackOverflow. I'm following a tutorial. I've created a new activity using a wizard. I get NullPointerException when attempting to call ...
  • 149k
979 votes
40 answers
496k views

onActivityResult is not being called in Fragment

The activity hosting this fragment has its onActivityResult called when the camera activity returns. My fragment starts an activity for a result with the intent sent for the camera to take a picture. ...
  • 39.5k
762 votes
21 answers
1.1m views

How do I get the current GPS location programmatically in Android?

I need to get my current location using GPS programmatically. How can i achieve it?
  • 25.2k
3515 votes
77 answers
1.1m views

Why is the Android emulator so slow? How can we speed up the Android emulator? [closed]

I have got a 2.67  GHz Celeron processor, and 1.21  GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android Emulator should start fairly quickly on such a machine, but ...
713 votes
64 answers
511k views

How to check internet access on Android? InetAddress never times out

I got a AsyncTask that is supposed to check the network access to a host name. But the doInBackground() is never timed out. Anyone have a clue? public class HostAvailabilityTask extends AsyncTask<...
567 votes
34 answers
501k views

Change app language programmatically in Android

Is it possible to change the language of an app programmatically while still using Android resources? If not, is it possible to request a resource in an specific language? I would like to let the ...
  • 118k
827 votes
31 answers
647k views

How do I add a library project to Android Studio?

How do I add a library project (such as Sherlock ABS) to Android Studio? (Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)
608 votes
17 answers
311k views

How to declare global variables in Android?

I am creating an application which requires login. I created the main and the login activity. In the main activity onCreate method I added the following condition: public void onCreate(Bundle ...
  • 65.7k
779 votes
16 answers
390k views

Best practice for instantiating a new Android Fragment

I have seen two general practices to instantiate a new Fragment in an application: Fragment newFragment = new MyFragment(); and Fragment newFragment = MyFragment.newInstance(); The second option ...
  • 25.6k

1
2 3 4 5
3029