App crashes when Home or Back button press - java

So, my app crashes when I press Home button or Back button. I don't know how to solve this issue. Help!!!
public class Game extends SurfaceView implements SurfaceHolder.Callback {
public Game(Context context) {
super(context);
getHolder().addCallback(this);
gameContext = context;
}
...
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
updateThread.setRunning(false);
while (retry) {
try {updateThread.join();
retry = false; }
catch (InterruptedException e) {
}
}
}
}
And here is a log of process when I press Home button:
07-15 07:43:47.333: I/ActivityManager(285): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} from pid 285
07-15 07:43:47.673: W/WindowManager(285): Screenshot failure taking screenshot for (290x515) to layer 21015
07-15 07:43:48.013: D/gralloc(36): Registering a buffer in the process that created it. This may cause memory ordering problems.
07-15 07:43:48.043: I/ARMAssembler(36): generated scanline__00000077:03010104_00008004_00000000 [ 84 ipp] (103 ins) at [0x4296eea0:0x4296f03c] in 599261 ns
07-15 07:43:48.464: D/gralloc(36): Registering a buffer in the process that created it. This may cause memory ordering problems.
07-15 07:43:48.504: I/ActivityManager(285): Config changes=1480 {1.0 310mcc260mnc en_US ldltr sw360dp w360dp h567dp 320dpi nrml port finger -keyb/v/h tball/v s.8}
07-15 07:43:48.574: I/InputReader(285): Reconfiguring input devices. changes=0x00000004
07-15 07:43:48.574: I/InputReader(285): Device reconfigured: id=0, name='qwerty2', size 720x1280, orientation 0, mode 1, display id 0
07-15 07:43:49.003: I/Choreographer(560): Skipped 168 frames! The application may be doing too much work on its main thread.
07-15 07:43:49.343: D/PhoneStatusBar(560): mSettingsPanelGravity = 55
07-15 07:43:49.593: D/dalvikvm(560): GC_FOR_ALLOC freed 7091K, 51% free 7087K/14336K, paused 111ms, total 131ms
07-15 07:43:49.743: W/WindowManager(285): Window freeze timeout expired.
07-15 07:43:49.743: W/WindowManager(285): Force clearing orientation change: Window{41ada620 u0 NavigationBar}
07-15 07:43:49.824: I/WindowManager(285): Screen frozen for +2s101ms due to Window{41ada620 u0 NavigationBar}
07-15 07:43:50.194: I/Choreographer(560): Skipped 124 frames! The application may be doing too much work on its main thread.
07-15 07:43:50.803: I/Choreographer(400): Skipped 119 frames! The application may be doing too much work on its main thread.
07-15 07:43:51.783: I/Choreographer(400): Skipped 106 frames! The application may be doing too much work on its main thread.
07-15 07:43:52.493: I/Choreographer(560): Skipped 194 frames! The application may be doing too much work on its main thread.
07-15 07:43:53.105: W/IInputConnectionWrapper(799): showStatusIcon on inactive InputConnection
07-15 07:43:54.173: D/dalvikvm(285): GC_EXPLICIT freed 3158K, 52% free 5244K/10724K, paused 5ms+11ms, total 134ms

try releasing resources which are consuming memory whenever they are in no use and you can do this in onPause() methods
you can also make some changes in manifiest.xml file like this
<activity android:name="your.package.name.YourActivity" android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize" android:screenOrientation="landscape">
...

Related

Java Android Studio Application working very slowly and laggy

The application is very laggy and the more things are being clicked, the more it lags. At some point it completely freezes. This is my error log. How can i optimize it? (Full beginner)
NativeAlloc concurrent copying GC freed 8231(560KB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 5936KB/11MB, paused 44.140ms total 1.790s
I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=820ms; Flags=0, IntendedVsync=12357482298756, Vsync=12357982298736, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=12358003456500, AnimationStart=12358003547700, PerformTraversalsStart=12358005401700, DrawStart=12358023891800, SyncQueued=12358058644400, SyncStart=12358063300300, IssueDrawCommandsStart=12358065361800, SwapBuffers=12358274912900, FrameCompleted=12358307408500, DequeueBufferDuration=3954100, QueueBufferDuration=21280700, GpuCompleted=0,
I/ample.indistan: Thread[5,tid=11901,WaitingInMainSignalCatcherLoop,Thread*=0xdf380010,peer=0x13600268,"Signal Catcher"]: reacting to signal 3
I/ample.indistan: Mutator lock exclusive owner tid: 18446744073709551615
ThreadList lock owner tid: 11919
ClassLinker classes lock owner tid: 0
ClassLinker dex lock owner tid: 0
I/ample.indistan: Waiting for a blocking GC ObjectsAllocated
I/ample.indistan: NativeAlloc concurrent copying GC freed 4035(425KB) AllocSpace objects, 3(60KB) LOS objects, 49% free, 5972KB/11MB, paused 2.528ms total 289.491ms
I/ample.indistan: WaitForGcToComplete blocked ObjectsAllocated on ProfileSaver for 5.863ms
I/ample.indistan: Wrote stack traces to tombstoned
I/Choreographer: Skipped 205 frames! The application may be doing too much work on its main thread.
W/ample.indistan: Verification of boolean androidx.core.view.KeyEventDispatcher.actionBarOnMenuKeyEventPre28(android.app.ActionBar, android.view.KeyEvent) took 105.167ms (494.45 bytecodes/s) (1768B approximate peak alloc)
W/ample.indistan: Verification of boolean androidx.core.view.KeyEventDispatcher.activitySuperDispatchKeyEventPre28(android.app.Activity, android.view.KeyEvent) took 126.372ms (538.09 bytecodes/s) (1728B approximate peak alloc)
V/FA: Recording user engagement, ms: 63317
I/Choreographer: Skipped 322 frames! The application may be doing too much work on its main thread.
V/FA: Connecting to remote service
V/FA: onActivityCreated
V/FA: Connection attempt already in progress
V/FA: Activity paused, time: 12386204
V/FA: Activity resumed, time: 12391211
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
I/Choreographer: Skipped 267 frames! The application may be doing too much work on its main thread.
W/RecyclerView: No adapter attached; skipping layout
I/OpenGLRenderer: Davey! duration=5309ms; Flags=1, IntendedVsync=12387232708368, Vsync=12391682708190, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=12391699342600, AnimationStart=12391699362500, PerformTraversalsStart=12391709661200, DrawStart=12392393938500, SyncQueued=12392471934000, SyncStart=12392475519700, IssueDrawCommandsStart=12392475611700, SwapBuffers=12392518233700, FrameCompleted=12392545949800, DequeueBufferDuration=1156600, QueueBufferDuration=14934400, GpuCompleted=8223625903103697763,
I/OpenGLRenderer: Davey! duration=5411ms; Flags=1, IntendedVsync=12387232708368, Vsync=12391682708190, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=12391699342600, AnimationStart=12391699362500, PerformTraversalsStart=12391709661200, DrawStart=12392632905600, SyncQueued=12392639112300, SyncStart=12392640203300, IssueDrawCommandsStart=12392641107800, SwapBuffers=12392643554700, FrameCompleted=12392645523900, DequeueBufferDuration=514100, QueueBufferDuration=1073700, GpuCompleted=185817465094143,
I/Choreographer: Skipped 154 frames! The application may be doing too much work on its main thread.
W/RecyclerView: No adapter attached; skipping layout
I/OpenGLRenderer: Davey! duration=2957ms; Flags=0, IntendedVsync=12391732774600, Vsync=12394299441164, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=12394309810900, AnimationStart=12394309826300, PerformTraversalsStart=12394327757600, DrawStart=12394468721300, SyncQueued=12394483804300, SyncStart=12394518606400, IssueDrawCommandsStart=12394523119100, SwapBuffers=12394667312700, FrameCompleted=12394725342600, DequeueBufferDuration=6457800, QueueBufferDuration=19058700, GpuCompleted=2314885530818453536,
I/Choreographer: Skipped 122 frames! The application may be doing too much work on its main thread.

Sudden app shutdown without doing any activity, throws IllegalStateException onMeasure()

My app always shutdown in random time interval (mostly from few minutes to something like 20 mins). The "App stopped working" messagebox appears. Biggest problem is, I don't do anything in app (like interacting with it), and it just random shutdown by itself. Here's logcat print:
07-15 20:34:16.595 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 141
9K, 44% free 13902K/24391K, paused 4ms+9ms, total 66ms
07-15 20:34:28.997 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1416K, 43% free 13903K/24391K, paused 3ms+7ms, total 56ms
07-15 20:34:29.418 27361-27361/test.game D/AndroidRuntime: Shutting down VM
07-15 20:34:29.418 27361-27361/test.game W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x412b52a0)
07-15 20:34:29.498 27361-27361/test.game E/AndroidRuntime: FATAL EXCEPTION: main java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
at android.view.View.measure(View.java:15293)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
at android.view.View.measure(View.java:15288)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
One would say, it's because I didn't write setMeasuredDimension() when overriding method onMeasure(). Also, docs say you have to write this line to your onMeasure, otherwise the IllegalStateException will be thrown (see it here).
But I don't overriding onMeasure anywhere in my whole project, so problem is not here (at least not on my side in this case).
Few things to note:
this is full logcat log, and any of these lines ("at android. ...") doesn't link to my code, all goes to source - that means all of these links are gray
this exception always happens only on my S3 Mini (android 4.1.2), but never happened on my old Galaxy Ace S5830i (android 2.3.6) (and yes, I tested it alot - over 20hours on old phone and app still running!).
never happened in emulator
there are no "view resizing" operations running in background, which could cause this exception
I would like to post some code, but I have absolutely no idea where this exception could be thrown.
If someone can help, I'd be really, really grateful. I'm lost at this point...
Since there is not code, this is just a random guess. You can start by looking out for activities in which you've added fragments. It might be that the activity containing a fragment has been destroyed on the device due to inactivity for a long time(and memory requirements by the system, which I think is the reason that you are finding the bug on a device and not on the other). So the case is that the fragment might be referring to a view which might not be attached to the window now. (You can also look for views that use fragment adapters like viewPager, etc if you have used them).

Sudden shutdown with IllegalStateException without doing anything

After 26 minutes leaving my app running without doing anything with it as a user, "app has stopped" window suddenly pop up and Logcat prints only this:
07-15 20:34:16.595 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1419K, 44% free 13902K/24391K, paused 4ms+9ms, total 66ms
07-15 20:34:28.997 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1416K, 43% free 13903K/24391K, paused 3ms+7ms, total 56ms
07-15 20:34:29.418 27361-27361/test.game D/AndroidRuntime: Shutting down VM
07-15 20:34:29.418 27361-27361/test.game W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x412b52a0)
07-15 20:34:29.498 27361-27361/test.game E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
at android.view.View.measure(View.java:15293)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
at android.view.View.measure(View.java:15288)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Any ideas where could be problem? It happened now for 2nd time (1st time it happened slightly sooner, in about ~13 mins), so it's not some "random" issue.
I can't provide any sample code since none of the Logcat errors links to my code (all goes to the source of specific View). Another strange behaviour is, this happened twice on my S3 Mini (in mentioned 13 and 26 mins), but didn't happened yet on my old Ace S5830i - app is running 4 hours 9 minutes and still nothing here!
edit n1:
Only thing which is running on background is Timer executed each 17ms. I'm displaying hours, minutes, seconds and milis on screen thanks to it.
timer.scheduleAtFixedRate(new TimerTask() ...
currentTime = System.currentTimeMillis() - start;
milisecond = currentTime % 1000;
long x = currentTime / 1000;
second = x % 60;
x /= 60;
minute = x % 60;
x /= 60;
hour = x % 24;
variable start is another System.currentTimeMillis(). It has still value, assigned when this Timer was created.
It's also possible that S3 Mini was a bit "overworked", because I've been developing and testing on it from computer all the day (and the newest Android Studio eats quite a lot memory in phone against AS v1.0.0). I'll try another tests tomorow and let you know how it ended.

I want the user to pass my login requirement in order to sign in

I want the intent I have below to be passed only when the user has passed the login requirements. I tried to put an if statement, in the onClick Listener but it wasn't working out. Basically, once the username and password meets my requirements, I want to pass the intent. If the intent doesn't pass, then I want to pass an else statement saying "That user doesn't exist."
10-20 16:53:10.330 2138-2138/com.squarespace.atpublishing.officialworkoutapp
I/art: Not late-enabling -Xcheck:jni (already on)
10-20 16:53:11.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 220ms
10-20 16:53:11.640 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 1555(94KB) AllocSpace objects, 0(0B) LOS objects, 33% free, 417KB/623KB, paused 0 total 130ms
10-20 16:53:11.850 2138-2138/com.squarespace.atpublishing.officialworkoutapp W/art: Verification of boolean android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(int, android.view.Menu) took 170ms
10-20 16:53:11.850 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 130ms
10-20 16:53:12.780 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 80ms
10-20 16:53:13.660 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms
10-20 16:53:13.900 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 10ms
10-20 16:53:13.900 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 1031(117KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 781KB/1017KB, paused 10ms total 60ms
10-20 16:53:14.340 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 10ms
10-20 16:53:14.340 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 282(24KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 878KB/1017KB, paused 10ms total 80ms
10-20 16:53:14.460 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background partial concurrent mark sweep GC freed 297(33KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 885KB/1397KB, paused 0 total 120ms
10-20 16:53:14.630 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 16:53:14.900 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/OpenGLRenderer: Render dirty regions requested: true
10-20 16:53:14.950 2138-2138/com.squarespace.atpublishing.officialworkoutapp D/: HostConnection::get() New Host Connection established 0x7fb36d6b8620, tid 2138
10-20 16:53:14.960 2138-2138/com.squarespace.atpublishing.officialworkoutapp D/Atlas: Validating map...
10-20 16:53:15.260 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/: HostConnection::get() New Host Connection established 0x7fb36d6ec100, tid 2229
10-20 16:53:15.350 2138-2229/com.squarespace.atpublishing.officialworkoutapp I/OpenGLRenderer: Initialized EGL, version 1.4
10-20 16:53:15.430 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/OpenGLRenderer: Enabling debug mode 0
10-20 16:53:15.440 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-20 16:53:15.440 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d6b7b00, error=EGL_SUCCESS
10-20 16:53:15.620 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms
10-20 16:53:15.650 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
10-20 16:53:20.900 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 40ms
10-20 16:53:20.930 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 16:53:21.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 190ms
10-20 16:53:21.660 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 102 frames! The application may be doing too much work on its main thread.
10-20 12:53:24.100 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 278(36KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 1242KB/1397KB, paused 0 total 190ms
10-20 12:53:25.100 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 70ms
10-20 12:53:26.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms
10-20 12:53:27.000 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 12:53:27.330 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 149 frames! The application may be doing too much work on its main thread.
10-20 12:53:27.770 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-20 12:53:27.770 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d2e6900, error=EGL_SUCCESS
10-20 12:53:28.120 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 47 frames! The application may be doing too much work on its main thread.
10-20 12:53:28.220 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-20 12:53:28.220 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d2e69c0, error=EGL_SUCCESS
10-20 12:53:28.270 2138-2138/com.squarespace.atpublishing.officialworkoutapp W/View: requestLayout() improperly called by android.support.design.internal.NavigationMenuView{2c5956e4 VFED.VC. ......ID 0,0-384,800} during layout: running second layout pass
10-20 12:53:28.460 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms
10-20 12:53:29.040 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
`
Button mEmailSignInButton = (Button)
findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
attemptLogin();
if (mPasswordView.getText().toString().isEmpty() && mEmailSignInButton.getText().toString().isEmpty()){
Snackbar.make(view, "You Didn't enter anything", Snackbar.LENGTH_LONG).setAction("Action", null);
} else {
Intent intent = new Intent(LoginActivity.this, DrawerActivity.class);
startActivity(intent);
}
Intent intent = new Intent(LoginActivity.this, DrawerActivity.class);
startActivity(intent);
}
});
/**
* Attempts to sign in or register the account specified by the login form.
* If there are form errors (invalid email, missing fields, etc.), the
* errors are presented and no actual login attempt is made.
*/
private void attemptLogin() {
if (mAuthTask != null) {
return;
}
// Reset errors.
mEmailView.setError(null);
mPasswordView.setError(null);
// Store values at the time of the login attempt.
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
boolean cancel = false;
View focusView = null;
// Check for a valid password, if the user entered one.
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordView.setError(getString(R.string.error_invalid_password));
focusView = mPasswordView;
cancel = true;
}
// Check for a valid email address.
if (TextUtils.isEmpty(email)) {
mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView;
cancel = true;
} else if (!isEmailValid(email)) {
mEmailView.setError(getString(R.string.error_invalid_email));
focusView = mEmailView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
showProgress(true);
mAuthTask = new UserLoginTask(email, password);
mAuthTask.execute((Void) null)
}
}
Your attemptLogin(); needs to be called within the else { } of your if.
Currently, it's being called before your if, so it will attempt to login even if your email or password fields are empty.
This was probably just an oversight on your part. If not, you might want to brush on Java by doing the exercises on the following web site. http://codingbat.com/java

Unable to make post request in android

I am a very new to android and have followed various tutorials on making a post request in android programming.What i want to do is loging to https://ubresources.com. below is my java class
Results.java
package com.example.fetapp;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Results extends Activity {
private EditText email, pass;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
email = (EditText)findViewById(R.id.email);
pass = (EditText)findViewById(R.id.pass);
Button login = (Button)findViewById(R.id.login);
login.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
postLoginData();
startActivity(new Intent(Results.this, MainPage.class));
}
});
}
public void postLoginData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://ubresources.com/login.json");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", email.getText().toString);
nameValuePairs.add(new BasicNameValuePair("password", pass.getText().toString);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.d("Login", response.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
but still cannot get the response.Please help me out,my logcat info looks is
09-11 17:35:54.244: I/Choreographer(1197): Skipped 73 frames! The application may be doing too much work on its main thread.
09-11 17:35:54.284: D/gralloc_goldfish(1197): Emulator without GPU emulation detected.
09-11 17:35:55.916: I/Choreographer(1197): Skipped 90 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.014: I/Choreographer(1197): Skipped 56 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.114: I/Choreographer(1197): Skipped 46 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.224: I/Choreographer(1197): Skipped 53 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.324: I/Choreographer(1197): Skipped 46 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.434: I/Choreographer(1197): Skipped 42 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.553: I/Choreographer(1197): Skipped 71 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.653: I/Choreographer(1197): Skipped 65 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.763: I/Choreographer(1197): Skipped 52 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.853: I/Choreographer(1197): Skipped 41 frames! The application may be doing too much work on its main thread.
09-11 17:35:57.204: I/Choreographer(1197): Skipped 39 frames! The application may be doing too much work on its main thread.
09-11 17:35:57.474: D/dalvikvm(1197): GC_FOR_ALLOC freed 217K, 5% free 6298K/6599K, paused 63ms, total 66ms
09-11 17:35:57.593: D/dalvikvm(1197): GC_FOR_ALLOC freed 198K, 6% free 6384K/6727K, paused 68ms, total 69ms
09-11 17:35:57.623: I/dalvikvm-heap(1197): Grow heap (frag case) to 7.392MB for 1165616-byte allocation
09-11 17:35:57.773: D/dalvikvm(1197): GC_CONCURRENT freed <1K, 5% free 7522K/7879K, paused 22ms+29ms, total 153ms
09-11 17:35:57.944: D/dalvikvm(1197): GC_FOR_ALLOC freed 0K, 5% free 7523K/7879K, paused 60ms, total 60ms
09-11 17:35:57.953: I/dalvikvm-heap(1197): Grow heap (frag case) to 7.887MB for 519172-byte allocation
09-11 17:35:58.074: D/dalvikvm(1197): GC_CONCURRENT freed 0K, 5% free 8030K/8391K, paused 20ms+9ms, total 120ms
09-11 17:35:58.074: D/dalvikvm(1197): WAIT_FOR_CONCURRENT_GC blocked 32ms
09-11 17:35:58.454: I/Choreographer(1197): Skipped 118 frames! The application may be doing too much work on its main thread.
09-11 17:35:59.164: I/Choreographer(1197): Skipped 193 frames! The application may be doing too much work on its main thread.
09-11 17:36:08.683: I/Choreographer(1197): Skipped 98 frames! The application may be doing too much work on its main thread.
09-11 17:36:08.803: I/Choreographer(1197): Skipped 63 frames! The application may be doing too much work on its main thread.
09-11 17:36:08.953: I/Choreographer(1197): Skipped 74 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.094: I/Choreographer(1197): Skipped 87 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.204: I/Choreographer(1197): Skipped 67 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.324: I/Choreographer(1197): Skipped 56 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.883: I/Choreographer(1197): Skipped 52 frames! The application may be doing too much work on its main thread.
09-11 17:36:10.004: I/Choreographer(1197): Skipped 56 frames! The application may be doing too much work on its main thread.
09-11 17:36:10.434: I/Choreographer(1197): Skipped 35 frames! The application may be doing too much work on its main thread.
09-11 17:36:10.833: I/Choreographer(1197): Skipped 87 frames! The application may be doing too much work on its main thread.
09-11 17:36:11.573: I/Choreographer(1197): Skipped 154 frames! The application may be doing too much work on its main thread.
09-11 17:36:16.523: I/Choreographer(1197): Skipped 78 frames! The application may be doing too much work on its main thread.
09-11 17:36:18.643: D/InputEventConsistencyVerifier(1197): KeyEvent: ACTION_UP but key was not down.
09-11 17:36:18.643: D/InputEventConsistencyVerifier(1197): in android.widget.EditText#4104d088
09-11 17:36:18.643: D/InputEventConsistencyVerifier(1197): 0: sent at 1890932000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=1890932, downTime=1890824, deviceId=0, source=0x101 }
09-11 17:36:30.733: I/Choreographer(1197): Skipped 36 frames! The application may be doing too much work on its main thread.
09-11 17:36:33.234: I/Choreographer(1197): Skipped 47 frames! The application may be doing too much work on its main thread.
09-11 17:36:34.583: D/AndroidRuntime(1197): Shutting down VM
09-11 17:36:34.583: W/dalvikvm(1197): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-11 17:36:34.653: E/AndroidRuntime(1197): FATAL EXCEPTION: main
09-11 17:36:34.653: E/AndroidRuntime(1197): android.os.NetworkOnMainThreadException
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.net.InetAddress.getAllByName(InetAddress.java:214)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.example.fetapp.Results.postLoginData(Results.java:61)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.example.fetapp.Results$1.onClick(Results.java:42)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.view.View.performClick(View.java:4084)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.view.View$PerformClick.run(View.java:16966)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.Handler.handleCallback(Handler.java:615)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.Handler.dispatchMessage(Handler.java:92)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.Looper.loop(Looper.java:137)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.lang.reflect.Method.invokeNative(Native Method)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.lang.reflect.Method.invoke(Method.java:511)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-11 17:36:34.653: E/AndroidRuntime(1197): at dalvik.system.NativeStart.main(Native Method)
09-11 17:41:34.804: I/Process(1197): Sending signal. PID: 1197 SIG: 9
09-11 17:41:35.924: E/Trace(1213): error opening trace file: No such file or directory (2)
09-11 17:41:36.934: D/dalvikvm(1213): GC_FOR_ALLOC freed 164K, 5% free 6132K/6407K, paused 87ms, total 91ms
09-11 17:41:37.483: I/Choreographer(1213): Skipped 82 frames! The application may be doing too much work on its main thread.
09-11 17:41:37.523: D/gralloc_goldfish(1213): Emulator without GPU emulation detected.
Try to use Retrofit library for that. It will also parse json for you. You will need only to create simple java object for your data.
Did you included the INTERNET permission on your app?
It seems your error happens either because you don't have Internet access or, less likely, permission to access the Internet.
Try reading Android's help about connecting to see if you didn't forget anything: http://developer.android.com/training/basics/network-ops/connecting.html
And make sure to try this, perhaps you're having the same problem: How to connect android emulator to the internet
The problem can be directly seen in your logcat.
NetworkOnMainThreadException
E/AndroidRuntime(1197): android.os.**NetworkOnMainThreadException** 09-11 17:36:34.653:
Here is a reference to the doc that basically says you can't do this.
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
The DefaultHttpClient is a rather low level class and as such tends to be much harder to use than say something like Retrofit
http://square.github.io/retrofit
Retrofit needs to be downloaded, and does take a little bit of setup, but in the long run you will be much happier using a much more highlevel api for Rest api calls.
Here is another good resource you might be interested in as well. It describes (or at least points you in the direction) of combining Squares's Retrofit and Otto (event bus) into a very nice way to communicate with a Restful web service
http://www.mdswanson.com/blog/2014/04/07/durable-android-rest-clients.html
Your problem there is you didn't implement AsyncTask when retrieving the response or maybe you did not add the permissions for internet / networking?
Try the android volley, it is the one recommended to use as it is owned by google as well as provides you faster networking access. If you try the android volley I can help you in many ways just reach me through my email or twitter. Cheers!

Categories

Resources