我尝试更改选项卡时,android模拟器不断崩溃

时间:2016-03-23 13:08:54

标签: android crash android-emulator freeze android-logcat

我的应用程序没有错误,但是当我切换标签时,它冻结并关闭模拟器中的应用程序,我是Android工作室和Android开发的新手。我不知道下一步该做什么。

这是我的logcat

03-23 11:56:05.749 2417-2417/com.example.hp_user.shoutfinal28 I/art: Not late-enabling -Xcheck:jni (already on)
03-23 11:56:05.994 2417-2417/com.example.hp_user.shoutfinal28 W/System: ClassLoader referenced unknown path: /data/app/com.example.hp_user.shoutfinal28-1/lib/x86
03-23 11:56:06.021 2417-2417/com.example.hp_user.shoutfinal28 I/GMPM: App measurement is starting up, version: 8487
03-23 11:56:06.021 2417-2417/com.example.hp_user.shoutfinal28 I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
03-23 11:56:06.032 2417-2417/com.example.hp_user.shoutfinal28 E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
03-23 11:56:06.032 2417-2417/com.example.hp_user.shoutfinal28 E/GMPM: Scheduler not set. Not logging error/warn.
03-23 11:56:06.209 2417-2433/com.example.hp_user.shoutfinal28 E/GMPM: Uploading is not possible. App measurement disabled
03-23 11:56:06.741 2417-2435/com.example.hp_user.shoutfinal28 D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-23 11:56:07.233 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 42.830ms
03-23 11:56:07.507 2417-2435/com.example.hp_user.shoutfinal28 I/OpenGLRenderer: Initialized EGL, version 1.4
03-23 11:56:07.670 2417-2435/com.example.hp_user.shoutfinal28 W/EGL_emulation: eglSurfaceAttrib not implemented
03-23 11:56:07.670 2417-2435/com.example.hp_user.shoutfinal28 W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad92f000, error=EGL_SUCCESS
03-23 11:56:07.874 2417-2417/com.example.hp_user.shoutfinal28 I/Choreographer: Skipped 46 frames!  The application may be doing too much work on its main thread.
03-23 11:56:09.040 2417-2417/com.example.hp_user.shoutfinal28 I/Choreographer: Skipped 67 frames!  The application may be doing too much work on its main thread.
03-23 11:56:14.016 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 10.772ms
03-23 11:56:16.753 2417-2433/com.example.hp_user.shoutfinal28 I/GMPM: Tag Manager is not found and thus will not be used
03-23 11:56:16.910 2417-2422/com.example.hp_user.shoutfinal28 I/art: Thread[2,tid=2422,WaitingInMainSignalCatcherLoop,Thread*=0xad90ed00,peer=0x12c7a0a0,"Signal Catcher"]: reacting to signal 3
03-23 11:56:17.048 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 46.962ms
03-23 11:56:17.211 2417-2422/com.example.hp_user.shoutfinal28 I/art: Wrote stack traces to '/data/anr/traces.txt'
03-23 11:56:22.415 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 6.324ms
03-23 11:56:33.717 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 12.067ms
03-23 11:56:39.211 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 17.079ms
03-23 11:57:13.188 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 12.698ms
03-23 11:57:15.690 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.155ms
03-23 11:57:19.158 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 11.179ms
03-23 11:57:21.138 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 10.996ms
03-23 11:57:40.748 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 11.140ms
03-23 11:57:46.163 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 6.413ms
03-23 11:57:57.981 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 8.603ms
03-23 11:58:00.909 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 12.863ms
03-23 11:58:04.638 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 21.404ms
03-23 11:58:18.369 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 21.777ms
03-23 11:58:24.334 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 31.972ms
03-23 11:58:24.769 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 12.558ms
03-23 11:58:25.399 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 21.461ms
03-23 11:58:35.213 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.951ms
03-23 11:58:38.694 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.319ms
03-23 11:58:51.712 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 10.430ms
03-23 11:59:08.130 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 11.958ms
03-23 11:59:16.520 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 12.715ms
03-23 11:59:28.920 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 31.685ms
03-23 11:59:29.423 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 15.909ms
03-23 11:59:30.402 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.648ms
03-23 11:59:30.923 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 16.189ms
03-23 11:59:57.004 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 6.171ms
03-23 12:00:04.514 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.080ms
03-23 12:00:05.500 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 21.063ms
03-23 12:00:09.465 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.965ms
03-23 12:00:19.918 2417-2423/com.example.hp_user.shoutfinal28 W/art: 

Suspending all threads took: 9.964ms
    03-23 12:00:21.427 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 17.293ms
    03-23 12:00:30.382 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 13.516ms
    03-23 12:01:20.767 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.766ms
    03-23 12:01:32.806 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 26.784ms
    03-23 12:01:33.904 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 36.950ms
    03-23 12:02:18.777 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 6.365ms
    03-23 12:02:39.284 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 14.412ms
    03-23 12:03:00.297 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 25.732ms
    03-23 12:03:01.280 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 8.056ms
    03-23 12:03:12.798 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.714ms
    03-23 12:03:17.801 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 8.841ms
    03-23 12:03:23.760 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.779ms
    03-23 12:03:44.725 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 13.453ms
    03-23 12:03:52.812 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 66.320ms
    03-23 12:03:57.738 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.062ms
    03-23 12:04:12.258 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.525ms
    03-23 12:04:14.760 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.565ms
    03-23 12:04:16.782 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 19.185ms
    03-23 12:04:23.730 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.169ms
    03-23 12:04:31.254 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 11.048ms
    03-23 12:04:38.743 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 10.787ms
    03-23 12:05:00.175 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 106.406ms
    03-23 12:05:02.590 2417-2435/com.example.hp_user.shoutfinal28 W/EGL_emulation: eglSurfaceAttrib not implemented
    03-23 12:05:02.590 2417-2435/com.example.hp_user.shoutfinal28 W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa21045c0, error=EGL_SUCCESS
    03-23 12:05:04.016 2417-2435/com.example.hp_user.shoutfinal28 E/Surface: getSlotFromBufferLocked: unknown buffer: 0xabfe4d10
    03-23 12:05:06.035 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 15606(1053KB) AllocSpace objects, 6(120KB) LOS objects, 37% free, 2MB/3MB, paused 19.193ms total 246.150ms
    03-23 12:05:06.076 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 16.765ms
    03-23 12:05:06.509 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 1885(1770KB) AllocSpace objects, 1(24KB) LOS objects, 39% free, 3MB/6MB, paused 24.099ms total 241.046ms
    03-23 12:05:06.553 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.531ms
    03-23 12:05:06.767 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 20.589ms
    03-23 12:05:06.918 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 1034(2MB) AllocSpace objects, 0(0B) LOS objects, 10% free, 5MB/6MB, paused 129.285ms total 303.506ms
    03-23 12:05:06.929 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 9.437ms
    03-23 12:05:07.075 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 39.477ms
    03-23 12:05:07.086 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 11.998ms
    03-23 12:05:07.187 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 464(1401KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 5MB/6MB, paused 65.404ms total 239.195ms
    03-23 12:05:07.220 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 31.710ms
    03-23 12:05:07.510 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 517(1538KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 7MB/11MB, paused 29.730ms total 245.372ms
    03-23 12:05:07.865 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 810(3MB) AllocSpace objects, 0(0B) LOS objects, 19% free, 8MB/11MB, paused 60.048ms total 195.013ms
    03-23 12:05:08.085 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.930ms
    03-23 12:05:08.097 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 558(2MB) AllocSpace objects, 0(0B) LOS objects, 2% free, 10MB/11MB, paused 57.680ms total 199.141ms
    03-23 12:05:08.372 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 330(1634KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 11MB/11MB, paused 45.586ms total 260.298ms
    03-23 12:05:08.593 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.991ms
    03-23 12:05:08.599 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 474(2MB) AllocSpace objects, 0(0B) LOS objects, 24% free, 12MB/16MB, paused 52.037ms total 213.333ms
    03-23 12:05:08.871 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 13.742ms
    03-23 12:05:08.973 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 1030(5MB) AllocSpace objects, 0(0B) LOS objects, 8% free, 15MB/16MB, paused 136.535ms total 320.111ms
    03-23 12:05:09.127 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 61.076ms
    03-23 12:05:09.133 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.412ms
    03-23 12:05:09.227 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 366(1835KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 17MB/17MB, paused 69.814ms total 225.055ms
    03-23 12:05:09.546 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 19.416ms
03-23 12:05:09.556 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 639(2MB) AllocSpace objects, 29(464KB) LOS objects, 17% free, 18MB/22MB, paused 70.188ms total 317.219ms
    03-23 12:05:09.576 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 19.102ms
    03-23 12:05:09.976 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 555(2MB) AllocSpace objects, 183(2MB) LOS objects, 10% free, 20MB/22MB, paused 79.907ms total 322.037ms
    03-23 12:05:09.989 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 11.923ms
    03-23 12:05:10.486 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 427(1679KB) AllocSpace objects, 140(2MB) LOS objects, 14% free, 23MB/27MB, paused 72.435ms total 402.265ms
    03-23 12:05:10.875 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 501(2005KB) AllocSpace objects, 165(2MB) LOS objects, 7% free, 25MB/27MB, paused 81.908ms total 324.161ms
    03-23 12:05:10.884 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.802ms
    03-23 12:05:11.172 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 165.365ms
    03-23 12:05:11.288 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 273(1063KB) AllocSpace objects, 89(1424KB) LOS objects, 12% free, 27MB/31MB, paused 75.815ms total 355.692ms
    03-23 12:05:11.747 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 230.989ms
    03-23 12:05:11.778 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 5.070ms
    03-23 12:05:11.905 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 447(1787KB) AllocSpace objects, 147(2MB) LOS objects, 12% free, 27MB/31MB, paused 121.279ms total 547.928ms
    03-23 12:05:11.913 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.013ms
    03-23 12:05:12.200 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 144.899ms
    03-23 12:05:12.218 2417-2427/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 7.041ms
    03-23 12:05:12.394 2417-2427/com.example.hp_user.shoutfinal28 I/art: Clamp target GC heap from 32MB to 32MB
    03-23 12:05:12.394 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background partial concurrent mark sweep GC freed 303(1183KB) AllocSpace objects, 98(1952KB) LOS objects, 10% free, 28MB/32MB, paused 167.749ms total 431.021ms
    03-23 12:05:12.555 2417-2417/com.example.hp_user.shoutfinal28 I/art: Waiting for a blocking GC Alloc
    03-23 12:05:12.629 2417-2423/com.example.hp_user.shoutfinal28 W/art: Suspending all threads took: 147.707ms
    03-23 12:05:12.730 2417-2427/com.example.hp_user.shoutfinal28 I/art: Background sticky concurrent mark sweep GC freed 242(978KB) AllocSpace objects, 80(1600KB) LOS objects, 7% free, 29MB/32MB, paused 86.419ms total 299.323ms
    03-23 12:05:12.732 2417-2417/com.example.hp_user.shoutfinal28 I/art: WaitForGcToComplete blocked for 177.147ms for cause Alloc
    03-23 12:05:12.733 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:12.769 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:12.769 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:13.069 2417-2417/com.example.hp_user.shoutfinal28 I/art: Clamp target GC heap from 34MB to 32MB
    03-23 12:05:13.069 2417-2417/com.example.hp_user.shoutfinal28 I/art: Alloc partial concurrent mark sweep GC freed 168(604KB) AllocSpace objects, 51(1020KB) LOS objects, 5% free, 30MB/32MB, paused 65.635ms total 298.511ms
    03-23 12:05:13.101 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:13.102 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
03-23 12:05:13.321 2417-2417/com.example.hp_user.shoutfinal28 I/art: Alloc sticky concurrent mark sweep GC freed 74(301KB) AllocSpace objects, 24(480KB) LOS objects, 4% free, 30MB/32MB, paused 62.666ms total 217.832ms
    03-23 12:05:13.329 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:13.329 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:13.643 2417-2417/com.example.hp_user.shoutfinal28 I/art: Clamp target GC heap from 34MB to 32MB
    03-23 12:05:13.643 2417-2417/com.example.hp_user.shoutfinal28 I/art: Alloc partial concurrent mark sweep GC freed 48(145KB) AllocSpace objects, 14(280KB) LOS objects, 4% free, 30MB/32MB, paused 63.546ms total 312.988ms
    03-23 12:05:13.660 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:13.661 2417-2417/com.example.hp_user.shoutfinal28 I/art: Starting a blocking GC Alloc
    03-23 12:05:13.870 2417-2417/com.example.hp_user.shoutfinal28 I/art: Alloc sticky concurrent mark sweep GC freed 31(37KB) AllocSpace objects, 26(468KB) LOS objects, 3% free, 30MB/32MB, paused 63.375ms total 208.351ms
    03-23 12:05:13.877 2417-2417/com.example.hp_user.shoutfinal28 I/art:                         Starting a blocking GC Alloc

我相信这是导致它崩溃的类,在我创建这个类和第4个标签之前我的应用程序运行良好,但除了标签之外其他两个类几乎是空的。

package com.example.hp_user.shoutfinal28;


import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;


public class FragmentShouts_Maps extends Fragment implements OnMapReadyCallback {


public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Get the view from fragment shouts.xml
    View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
    SupportMapFragment fragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.maps);
    if (fragment!= null) {
        fragment.getMapAsync(this);
    }
    return view;
}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);




}

@Override
public void onMapReady (GoogleMap googleMap) {

}



}

这是我的ViewPagerAdapter

public class ViewPagerAdapter extends FragmentPagerAdapter {

final int PAGE_COUNT = 4;
// Tab Titles
private String tabtitles[] = new String[] {"Home","Shouts","Maps","Shouters"};
Context context;

public ViewPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public int getCount() {
    return PAGE_COUNT;
}


public Fragment getItem(int position) {
    switch (position) {

        // Open Fragment home.java
        case 0:
            FragmentHome fragmenthome = new FragmentHome();
            return fragmenthome;

        // Open Fragment shouters.java
        case 1:
            FragmentShouts fragmentshouts = new FragmentShouts();
            return fragmentshouts;

        case 2:
            FragmentShouts_Maps fragmentshouts_maps = new FragmentShouts_Maps();
            return fragmentshouts_maps;

        case 3:
            FragmentShouters fragmentshouters = new FragmentShouters();
            return fragmentshouters;



    }
    return null;
}

@Override
public CharSequence getPageTitle(int position) {
    return tabtitles[position];
}

这是我的主要活动类,我想我稍微同意你,它是一个滑动标签条,这对于Android来说是不自然的,在ios设备中更常见,它在第四个标签的实现之前运行顺利但我注意到了单击按钮后存储用户输入时,toast会缓慢反应

public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from activity_main.xml
    setContentView(R.layout.activity_main);

    // Locate the viewpager in activity_main.xml
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

    // Set the ViewPagerAdapter into ViewPager
    viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));

}

public void btnShout(View v) {
    //allows for label to be changed to shouted once button is pressed
    EditText txtInput = (EditText) findViewById(R.id.txtInput);
    TextView lblShout = (TextView) findViewById(R.id.lblShout);
    lblShout.setText("Shouted! ");

    //allows for toast to be displayed once button is clicked
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
    toast.makeText(MainActivity.this, txtInput.getText() + " Has Been Shouted.", toast.LENGTH_SHORT).show();

}

}

1 个答案:

答案 0 :(得分:0)

你在主线程上做了太多工作。

03-23 11:56:07.874 2417-2417/com.example.hp_user.shoutfinal28 I/Choreographer: Skipped 46 frames!  The application may be doing too much work on its main thread.
03-23 11:56:09.040 2417-2417/com.example.hp_user.shoutfinal28 I/Choreographer: Skipped 67 frames!  The application may be doing too much work on its main thread.

如果您需要执行长时间运行的代码,则应该查看Android的线程工具(http://developer.android.com/guide/components/processes-and-threads.htmlhttp://developer.android.com/training/multiple-threads/index.html)。 AsyncTaskhttp://developer.android.com/reference/android/os/AsyncTask.html)是你的朋友=)