android


Android ANR when trying to start service


I have a service which has been working perfectly for weeks, and in the last day has suddenly started having problems. I know I've added something recently which triggered this behavior but looking back through my GIT logs I can't find anything that seems obvious so I'm going to try to see if anyone can help me understand what is actually happening instead.
From a button click in a fragment I call the following method:
private void performEnterCalibrationMode(Intent intent) {
Log.d(TAG, "Creating calibration mode task.");
final CalibrationModeTask calTask = new CalibrationModeTask(CALIBRATION_MODE.ENTER_CALIBRATION_MODE);
intent.putExtra(TekCast.EXTRA_TASK, calTask);
intent.putExtra(TekCast.EXTRA_TASK_COMPLETE_CALLBACK, this);
Log.d(TAG, "Broadcasting calibration mode task intent.");
mContext.startService(intent);
Log.d(TAG, "Intent was broadcast.");
}
I see the "Intent was broadcast" message in my log, so I know I've made it that far.
The service's onCreate() method is as follows:
#Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "CommunicationService onCreate()");
// Setup the background thread and its controls
HandlerThread thread = new HandlerThread("TekDAQC Communication Service", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper, this);
mLocalBroadcastMgr = LocalBroadcastManager.getInstance(getApplicationContext());
// Initialize the session map
mCommSessions = new ConcurrentHashMap<String, ASCIICommunicationSession>();
}
The service's onStartCommand() method is as follows:
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Extract the service instruction
final String action = intent.getAction();
Log.d(TAG, "Received start command: " + action);
// Build the message parameters
Bundle extras = intent.getExtras();
if (extras == null)
extras = new Bundle();
extras.putString(TekCast.EXTRA_SERVICE_ACTION, action);
// Run each task in a background thread.
final Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.setData(extras);
Log.d(TAG, "Sending message to background thread.");
mServiceHandler.sendMessage(msg);
return Service.START_NOT_STICKY;
}
None of the log statements from onStartCommand() or onCreate() for the service are ever called. Instead, I get the following stack trace and an ANR:
09-06 19:00:58.291: D/CalibrationSteps(2228): Creating calibration mode task.
09-06 19:00:58.291: D/CalibrationSteps(2228): Broadcasting calibration mode task intent.
09-06 19:00:58.601: I/art(2228): GcCauseBackground sticky partial concurrent mark sweep GC freed 50607(2MB) AllocSpace objects, 5(202KB) LOS objects, 5% free, 37MB/39MB, paused 9.869ms total 72.321ms
09-06 19:00:59.361: I/art(2228): GcCauseBackground sticky partial concurrent mark sweep GC freed 17890(841KB) AllocSpace objects, 0(0B) LOS objects, 5% free, 39MB/41MB, paused 11.853ms total 19.861ms
09-06 19:00:59.371: D/CalibrationSteps(2228): Intent was broadcast.
09-06 19:00:59.581: I/System.out(2228): Discovery timed out.
09-06 19:00:59.581: I/System.out(2228): Closing socket...
09-06 19:01:19.431: I/art(2228): Thread[5,tid=2234,WaitingInMainSignalCatcherLoop,Thread*=0x4749b3e8,peer=0x65551c10,"Signal Catcher"]: reacting to signal 3
09-06 19:01:19.511: I/art(2228): Wrote stack traces to '/data/anr/traces.txt'
I have added strict mode logging in my application's 'onCreate()' method, but it does not report anything:
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
And of course I have my service declared in my manifest (it has been working until today).
So ultimately my question is, what would cause an intent to send successfully but have an ANR reported rather than starting the service? Why is StrictMode not detecting it?
REQUESTED ADDITIONAL INFORMATION
The intent is passed to the performEnterCalibrationMode(Intent) method by the following code:
final Intent intent = new Intent(mContext, CommunicationService.class);
intent.setAction(ServiceAction.EXECUTE_TASK.toString());
UPDATE
It turns out the service is being started prior to this (I am able to send commands to it to connect). However, when I send this command after connecting (a second or two), thats when I get the ANR.

Related Links

Add EditText dynamically with (if possible) String id into a Fragment
Running under Android Studio's Run corrupts the stored view
How to check socket status from other classes in android?
How does an Android Studio deal with System.out.print functions when making a final version of an app?
MultiDex error after updating GCM gradle
cannot be cast to android.widget.Filterable in Xamarin
Unable to track overlapping of view objects in Android
Hide Toolbar on scrolling tab content
How to use a secondary Activity in a LiveWallpaper Engine
How to prepare a .aar for an .apk, without building a .apk? (Processing out ${applicationI})
After taking a picture, the app crashes when going to preview xamarin android
Slight latency in recycler view scrolling with multiple view holders
VPS as video relay server using ffmpeg and ffserver?
SntpClient and Android's Volley
Wrap AcroFields TextField in ItextG
Android app crashes if I declare more than 3 Drawables

Categories

HOME
google-app-engine
search
oracle12c
deep-learning
linkedin
android-studio-2.2
angular2-material
swt
fftw
apiblueprint
pclxl
scripting
hpc
odoo-8
opengl-3
boto3
endeca
azure-powershell
esoteric-languages
foreign-keys
href
react-toolbox
exploit
gpio
autodesk-designautomation
scatter3d
erb
hard-drive
nested-lists
video-capture
sql-server-ce
chef-solo
c9.io
naming
apollostack
android-checkbox
facebook-social-plugins
monkey-testing
optimizely
flask-restful
getchar
openrasta
serde
identification
lsyncd
offline.js
android-instrumentation
webjars
parfor
mta
cassia
lz77
nio2
blitline
piracy-prevention
rewrite
computer-architecture
lazybones
slash
eoferror
zscript
matlab-deployment
osc
j-security-check
rrule
beatsmusic
linkedin-jsapi
with-statement
koala
drupal-nodes
scriptaculous
inputmismatchexception
model-driven-development
nevron
flex++
poker
asplinkbutton
intersect
onmousemove
mkv
jquery-blockui
xcode3.2
adobe-media-server
jquery-address
workflow-services
promotion-code
landscape-portrait
filemerge
xcelsius
listactivity
socketserver
nstokenfield
visualj#
cardspace
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App