I am pretty new to Android and Java programming and was able to find a lot of solutions to my many questions here. However I find myself stuck now, without finding any solutions online.
I have written a simple app, which creates an onTouchListener in the onCreate-method of my MainActivity. info() starts a new InfoActivity.
If I kill my app and start it fresh, the first time I touch the info ImageView I see ACTION_DOWN and ACTION_UP in rapid succession and the new InfoActivity opens quickly.
However if I have resumed the MainActivity by either minimizing it or visiting the InfoActivity and returning (with finish()) now I notice a huge delay of about 2000ms between the ACTION_DOWN and ACTION_UP event. The new activity is also delayed the same way, even if I move the info() call in the ACTION_DOWN case like in the code here.
As far as I can tell nothing happens during those two seconds of delay.
Please respond with a method how I can troubleshoot this better. I realize there is probably an easy way to find out, but I have spent literally hours searching and nothing I tried brought me closer to a solution.
Best regards
Julius
info = (ImageView) findViewById(R.id.info);
info.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN: {
Log.i("MOTION_EVENT","ACTION DOWN");
info.setImageResource(R.drawable.infoback);
info();
Log.i("MOTION_EVENT","ACTION INFO");
break;
}
case MotionEvent.ACTION_CANCEL:{
Log.i("MOTION_EVENT","ACTION CANCEL");
info.setImageResource(R.drawable.info);
break;
}
case MotionEvent.ACTION_UP: {
Log.i("MOTION_EVENT","ACTION UP");
info.setImageResource(R.drawable.info);
break;
}
}
return true;
}
});
Log.i("TIMESTAMP","End onCreate");
Here's a log of starting the app, opening infoActivity, closing infoActivity and then trying to do so again, experiencing the slowdown.
06-29 02:12:12.529 15856-15856/de.juliusbier.shamebell I/TIMESTAMP﹕ Start onCreate
06-29 02:12:13.083 15856-15856/de.juliusbier.shamebell E/MediaPlayer﹕ Should have subtitle controller already set
06-29 02:12:13.083 15856-15856/de.juliusbier.shamebell I/TIMESTAMP﹕ End onCreate
06-29 02:12:13.084 15856-15856/de.juliusbier.shamebell I/TIMESTAMP﹕ Start onResume
06-29 02:12:13.084 15856-15856/de.juliusbier.shamebell I/SHAKER﹕ RESUME
06-29 02:12:13.084 15856-15856/de.juliusbier.shamebell I/TIMESTAMP﹕ End onResume
06-29 02:12:13.089 15856-15877/de.juliusbier.shamebell D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-29 02:12:13.092 15856-15856/de.juliusbier.shamebell D/Atlas﹕ Validating map...
06-29 02:12:13.099 15856-15856/de.juliusbier.shamebell E/MediaPlayer﹕ Should have subtitle controller already set
06-29 02:12:13.128 15856-15877/de.juliusbier.shamebell I/Adreno﹕ EGLInit: QTI Build: 01/29/15, 1bccc5d, I0ba6dce82d
06-29 02:12:13.138 15856-15877/de.juliusbier.shamebell I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-29 02:12:13.144 15856-15877/de.juliusbier.shamebell D/OpenGLRenderer﹕ Enabling debug mode 0
06-29 02:12:20.480 15856-15856/de.juliusbier.shamebell I/MOTION_EVENT﹕ ACTION DOWN
06-29 02:12:20.521 15856-15856/de.juliusbier.shamebell I/MOTION_EVENT﹕ ACTION INFO
06-29 02:12:20.557 15856-15856/de.juliusbier.shamebell I/MOTION_EVENT﹕ ACTION UP
06-29 02:12:20.563 15856-15856/de.juliusbier.shamebell I/INFO﹕ Start onCreate
06-29 02:12:20.578 15856-15856/de.juliusbier.shamebell I/INFO﹕ Finish onCreate
06-29 02:12:24.992 15856-15856/de.juliusbier.shamebell I/TIMESTAMP﹕ Start onResume
06-29 02:12:24.993 15856-15856/de.juliusbier.shamebell I/SHAKER﹕ RESUME
06-29 02:12:24.993 15856-15856/de.juliusbier.shamebell I/TIMESTAMP﹕ End onResume
06-29 02:13:03.367 15856-15856/de.juliusbier.shamebell I/MOTION_EVENT﹕ ACTION DOWN
06-29 02:13:03.375 15856-15856/de.juliusbier.shamebell I/MOTION_EVENT﹕ ACTION INFO
-----------------------------Here comes the delay-------------------------------------
06-29 02:13:05.540 15856-15856/de.juliusbier.shamebell I/MOTION_EVENT﹕ ACTION UP
06-29 02:13:05.542 15856-15856/de.juliusbier.shamebell I/INFO﹕ Start onCreate
06-29 02:13:05.551 15856-15856/de.juliusbier.shamebell I/INFO﹕ Finish onCreate
UPDATE: Taking out the setImageResource calls solves the issue, it seems to me like the drawing is somehow delayed and the new activity is not openened until all setImageResources have been dealt with.
info = (ImageView) findViewById(R.id.info);
info.setImageResource(R.drawable.info_selector);
info.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
shaker.close();
Intent infoIntent = new Intent(getBaseContext(), InfoActivity.class);
startActivity(infoIntent);
}
});
With this code from Rajesh Batth, I get the same problems. Notice that the code in the onClick(View v) is my former info() method. shaker.close calls the following line in a shake detection class I adapted from the answer of this post:
mgr.unregisterListener(listener);
Not closing the shaker or even taking out the shake detection completely does not change anything.