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
2
votes
1 answer

Why can't I import android.os.StrictMode?

Why I am facing error at the import android.os.StrictMode? import android.os.StrictMode; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); --->StrictMode.ThreadPolicy policy = new…
Twister
  • 199
  • 3
  • 9
  • 19
1
vote
1 answer

How to wrap these classes into a AsyncClass and then using them?

I'm trying to put together a simple RSS reader, and found code on http://www.ibm.com/developerworks/opensource/library/x-android/ Todo so, I noticed that you can not do network operations from the main thread since Honeycomb and have a hard time…
Hiam
  • 303
  • 1
  • 4
  • 12
1
vote
1 answer

StrictMode is throwing DatabaseObjectNotClosedException when using CursorLoader and leaving the current activity

I'm using a very basic example where I create a CursorLoader with a uri from my content provider and populate a map. Everything works smoothly but when I leave that activity I get a DatabaseObjectNotClosedException thrown by StrictMode. I understand…
Catalin Morosan
  • 7,897
  • 11
  • 53
  • 73
1
vote
0 answers

How to fix StrictMode policy violation; ~duration=17 ms: android.os.strictmode.DiskReadViolation on call to startActivity(intent)

We have enabled strict mode in one of our activities to check for violations, getting a trace pointing to the startActivity() call belonging to the Activity class. I'm not sure why it's throwing this issue, as i do not see any IO calls being…
1
vote
2 answers

How to check the connection status in Android avoiding StrictMode

I created a function that returns a boolean based on the presence of an internet connection, this function it is called different times from different java classes. The only way that I find to use it is to use the StrictMode.setThreadPolicy (i know…
1
vote
2 answers

How to Fix Duplicated Paypal Button in React Strict Mode

Hi guys would like to know how to fix this issue after updating to React 18 I have a duplicated button due to the useEffect while in StrictMode. Any guide how to unsubscribe to this API call or maybe fix it using a proper cleanup. Thanks in…
1
vote
2 answers

Is there a way to ahead detect ANR programmatically in production?

StrictMode is designed to be used in development and is disabled by default without developer mode, so I'm wondering if there is a way to detect ANR condition ahead, in order to intervene properly before OS ends in ANR timeout that under a specific…
AndreaF
  • 11,975
  • 27
  • 102
  • 168
1
vote
1 answer

Android StrictMode Policy: A resource was acquired at attached stack trace but never released Error

I am using Image Compression method from this link it working fine if i compress single image but as soon as i give this method multiple images to compress in STRICT MODE app get crashed at ExifInterface exif = new ExifInterface(filePath); with…
Ritu
  • 518
  • 2
  • 12
  • 35
1
vote
1 answer

Android StrictMode java.lang.Throwable: Explicit termination method 'close' not called

i enable strict mode in my app and it crashed with an error boolean DEVELOPER_MODE=true; if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() …
Ritu
  • 518
  • 2
  • 12
  • 35
1
vote
0 answers

KeyguardManager.isKeyguardSecure cause StrictMode policy violation

I want to check whether the device screen lock is enabled or not and I am using the standard API provided by Android SDK as shown below. But I am receiving D/StrictMode: StrictMode policy violation; ~duration=127 ms:…
Code Wizard
  • 319
  • 3
  • 8
1
vote
0 answers

StrictMode shows 10 errors for one line of code

I am running StrictMode.enableDefaults() to clean up my code and I have one line of code that sets the ZoneId that gives 10 StrictMode violations at about 195ms each for the single line of code. The Log.d statement just above the line only shows…
mtdavem
  • 441
  • 1
  • 7
  • 17
1
vote
3 answers

Is it possible to avoid ANR using StrictMode in android?

Somewhere I read that By using StrictMode we can avoid ANR in android. I tried like that below is the code public class MyApplication extends Application { @Override public void onCreate() { StrictMode.setThreadPolicy(new…
Gaju Kollur
  • 2,046
  • 5
  • 23
  • 47
1
vote
0 answers

A resource was acquired at attached stack trace but never released in DynamiteModulesC

I am using Strict mode and am getting a lot of this errors. E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. java.lang.Throwable: Explicit…
1
vote
1 answer

Doing File I/O on Android - Which thread does it belong on

After reading Brad Fitzpatrick's article on StrictMode I'm left with a few questions. Where does File I/O belong in my applications? (I know the UI thread is wrong but could spawning a new thread be worse?) If I should use a thread for doing disk…
smith324
  • 13,020
  • 9
  • 37
  • 58
1
vote
0 answers

StrictMode with penaltyDeath closing the app

I have implemented StrictMode in my app with these options: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectNetwork() .penaltyLog() .build()); …
DroidDroid
  • 11
  • 3
1 2 3
8 9