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
230 votes
3 answers
40k 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....
kael's user avatar
  • 6,585
877 votes
23 answers
550k 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 ...
nhaarman's user avatar
  • 98.7k
2711 votes
64 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....
bejoy george's user avatar
  • 29.4k
1528 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-...
UMAR-MOBITSOLUTIONS's user avatar
319 votes
15 answers
136k 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 ...
183 votes
3 answers
575k views

How do I parse JSON in Android? [duplicate]

How do I parse a JSON feed in Android?
iamlukeyb's user avatar
  • 6,487
1386 votes
44 answers
650k 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. ...
2073 votes
41 answers
577k 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 ...
lostInTransit's user avatar
2861 votes
35 answers
901k 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; ...
Bernard's user avatar
  • 45.3k
59 votes
6 answers
46k 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 ...
Ilya S's user avatar
  • 751
598 votes
30 answers
749k 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?
Muhammad Maqsoodur Rehman's user avatar
190 votes
12 answers
120k 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: ...
Nathan Loudjani's user avatar
1100 votes
14 answers
903k 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), ...
Hesam's user avatar
  • 52.3k
699 votes
25 answers
473k 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 ...
Vinayak Bevinakatti's user avatar
3067 votes
54 answers
1.3m 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?
Tyler's user avatar
  • 31.3k
31 votes
4 answers
9k 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 ...
a_local_nobody's user avatar
1056 votes
23 answers
599k 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<...
Pongpat's user avatar
  • 13.2k
6336 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?
capecrawler's user avatar
  • 67.4k
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; /** ...
Fox's user avatar
  • 9,384
15 votes
1 answer
5k views

getContactsFromFirebase() method return an empty list

public List<String> getContactsFromFirebase(){ FirebaseDatabase.getInstance().getReference().child("Users") .addListenerForSingleValueEvent(new ValueEventListener() { ...
Panther007's user avatar
4317 votes
128 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 ...
1672 votes
37 answers
1.4m 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-...
david.s's user avatar
  • 17k
1128 votes
108 answers
905k 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 ...
Prolifixs's user avatar
  • 305
1247 votes
40 answers
295k 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 ...
1126 votes
16 answers
625k 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 ...
Tom Leese's user avatar
  • 19.3k
547 votes
26 answers
452k 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?
korovaisdead's user avatar
  • 6,271
913 votes
27 answers
615k 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 ...
Thomas Vos's user avatar
  • 12.3k
334 votes
14 answers
599k 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 ...
user3104719's user avatar
  • 3,465
673 votes
49 answers
795k 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 ...
CurtJRees's user avatar
  • 6,748
238 votes
13 answers
419k 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?
Harsha M V's user avatar
  • 54.1k
1000 votes
15 answers
250k 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 ...
Heikki Toivonen's user avatar
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 ...
Andy's user avatar
  • 10.6k
1960 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 ...
Niko Gamulin's user avatar
563 votes
31 answers
598k 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&...
Parth Patel's user avatar
  • 6,508
336 votes
5 answers
225k 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 ...
Muhammad Umar's user avatar
187 votes
12 answers
350k 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: ...
fullmoon's user avatar
  • 8,050
889 votes
35 answers
850k 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 ...
Adil Bhatty's user avatar
  • 17.2k
857 votes
28 answers
364k 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 ...
emmby's user avatar
  • 99.9k
361 votes
24 answers
603k 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 ...
user1302569's user avatar
  • 7,131
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 ...
laalto's user avatar
  • 150k
988 votes
40 answers
503k 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. ...
Spidy's user avatar
  • 39.8k
325 votes
38 answers
531k 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; ...
equitharn's user avatar
  • 3,453
765 votes
22 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?
mudit's user avatar
  • 25.3k
3528 votes
77 answers
1.1m views

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

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 ...
572 votes
35 answers
515k 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 ...
hpique's user avatar
  • 119k
781 votes
16 answers
397k 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 ...
Graham Smith's user avatar
  • 25.6k
828 votes
31 answers
650k 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.)
Alexander's user avatar
  • 47.8k
719 votes
64 answers
515k 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<...
Vidar Vestnes's user avatar
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 ...
Niko Gamulin's user avatar

1
2 3 4 5
3049