Questions tagged [android-strictmode]

This mode helps a developer to identify potential bugs in an app.

From Android Developer Docs:

StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them.

StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users.

135 questions
131
votes
6 answers

Should accessing SharedPreferences be done off the UI Thread?

With the release of Gingerbread, I have been experimenting with some of the new API's, one of them being StrictMode. I noticed that one of the warnings is for getSharedPreferences(). This is the warning: StrictMode policy violation; ~duration=1949…
cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171
54
votes
6 answers

Android StrictMode InstanceCountViolation

I am running my app with StrictMode activated in development as documented here StrictMode for lower platform versions and noticed an error message that I do not know what to think about nor can I find any reference. I get a…
Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
41
votes
7 answers

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks

I am getting this message in logcat A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. Where do I look for the leak and what does it mean by " See…
dreamer1989
  • 1,075
  • 3
  • 12
  • 29
37
votes
1 answer

Android P (API 28) - What does the StrictMode policy violation "SmartSelectionEventTracker$SelectionEvent;->selectionAction" mean?

I am using the StrictMode in order to find non-SDK usages: if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectNonSdkApiUsage() …
hamena314
  • 2,969
  • 5
  • 30
  • 57
26
votes
3 answers

StrictMode java.lang.Throwable: Untagged socket detected

With StrictMode enabled I just started getting this exception: java.lang.Throwable: Untagged socket detected; use TrafficStats.setThreadSocketTag() to track all network usage
Jose Gómez
  • 3,110
  • 2
  • 32
  • 54
22
votes
1 answer

How to debug leak caused by UnixDirectoryStream in Android app

After enabling StrictMode I noticed this: 2021-05-08 11:09:42.854 14347-14773/com.myapp D/StrictMode: StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See…
Mark
  • 7,446
  • 5
  • 55
  • 75
22
votes
0 answers

StrictMode policy violation: android.os.strictmode.LeakedClosableViolation in my app?

New to Android development and trying out StrictMode on my app for the first time. I noticed the following and would like to know if this is a problem in my app or a library—it’s not readily clear to me. Thank you! D/StrictMode: StrictMode policy…
Bink
  • 1,934
  • 1
  • 25
  • 41
20
votes
1 answer

DropBoxManager use cases?

I noticed that a DropBoxManager has been introduced in Android API since FroYo (API 8). It looks like an alternative logger capable of logging not only text but also files or byte arrays, but I could not find any detailed doc anywhere about how and…
Kevin Gaudin
  • 9,927
  • 3
  • 32
  • 34
16
votes
2 answers

Android Honeycomb: NetworkOnMainThreadException even when using AsyncTask and no strict mode?

I run into a NetworkOnMainThreadException with my Android 3.0 app. Searching for a solution I found this, but if I understand this correctly, default setting would be that the strict mode is turned off. Also, all my network access is in an…
15
votes
4 answers

Finding what violated StrictMode policy

I've enabled StrictMode in my app and it's causing a few crashes as expected. How can I find out where in my code I'm violating these policies? This is the stack trace: E/AndroidRuntime(19523): FATAL EXCEPTION: main E/AndroidRuntime(19523):…
copolii
  • 14,208
  • 10
  • 51
  • 80
13
votes
1 answer

StrictMode: How to disable "Untagged socket detected" in Android for targetSdk >= 28

I'm trying to disable one of Android StrictMode checks - detection of untagged sockets. I have several reasons to do this: Some libraries used in our app e.g. Crashlytics / Picasso e.t.c. are using OkHttp internally and StrictMode detects untagged…
Alexandr Shkurko
  • 323
  • 3
  • 12
12
votes
6 answers

StrictMode for lower platform versions

I have started using the Android StrictMode and find that it would be great to have it always running during development and not just on a special branch I created in git. The reason I did this is my apps requirement to run with 1.6 and up. I read…
Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
12
votes
6 answers

Gingerbread emulator instance is much more sluggish than Froyo and below. Why?

I'm not sure if anyone else noticed it, but the Gingerbread emulator runs like a dog, with both scrolling, navigating, interaction - all taking much longer and being much choppier. I even got an ANR in the browser when I tried to use it:…
11
votes
4 answers

Definition of DEVELOPER_MODE for StrictMode

I'm anxiously awaiting the open source release of StrictMode for continuation of our platform development. The sample in the Android blog entry suggests surrounding the StrictMode calls with if (DEVELOPER_MODE) { ... } For SDK development, I'd…
Dave Boldt
  • 111
  • 1
  • 3
10
votes
1 answer

Android StrictMode reporting false positives

I have been trying to run my application in StrictMode to check for any hidden problem that may have sneaked. One issue I ran across is what seems to be a false positive of Leaked DatabaseConections when using ContentResolver. After some experiments…
StefanK
  • 2,020
  • 2
  • 14
  • 16
1
2 3
8 9