2013-07-14 3 views
0

편집 : 내 주요 문제가 해결되었습니다. 이제는 하나의 활동을 열고 다음 활동으로 이동하는 데 문제가 있습니다. 내 이해에서 manifest는 ".Main"에게 splash.xml 파일을 여는 것을 지시합니다. sleep 명령은 ".menu"로 이동하는 것보다 5 초 동안 쉬어야하며 main.xml이 열립니다. 그러나 에뮬레이터에서이 응용 프로그램을 실행하면 main.xml 만 표시되고 5 초 소개는 건너 뜁니다. 이 코드는 최적의 코드를하지 않을 수 있습니다Android 슬립() 작동하지 않음

>**Main.java** 

>package com.pooks.thebasics; 

>import android.os.Bundle; 
>import android.app.Activity; 
import android.content.Intent; 

>public class Main extends Activity { 
> 
    @Override 
    protected void onCreate(Bundle TravisIsAwesome) { 
     super.onCreate(TravisIsAwesome); 
     setContentView(R.layout.splash); 
     Thread logoTimer = new Thread(){ 
      public void run(){ 
       try{ 
        sleep(5000); 
        Intent menuIntent = new Intent("com.pooks.thebasics.MENU"); 
        startActivity(menuIntent); 
       } catch (InterruptedException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
>    
       finally{ 
        finish(); 
       } 
      } 
     }; 
     logoTimer.start(); 
    } 
} 

    **splash.xml** 

    <?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/splash_back" 
      android:orientation="vertical" > 

     </LinearLayout> 



>**menu.java** 
> 
    package com.pooks.thebasics; 
    import android.app.Activity; 
    import android.os.Bundle; 
> 
    public class menu extends Activity { 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
     } 

     @Override 
     protected void onPause() { 
      // TODO Auto-generated method stub 
      super.onPause(); 
     } 
    } 



>**main.xml** 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:background="@drawable/background1" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="fill_parent" 
      android:layout_height="54dp" 
      android:gravity="center" 
      android:height="25dp" 
      android:lines="1" 
      android:paddingBottom="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_vertical_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      android:text="@string/hello_world" 
      android:textAppearance="?android:attr/textAppearanceSmallInverse" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="fill_parent" 
      android:layout_height="54dp" 
      android:height="25dp" 
      android:lines="1" 
      android:paddingBottom="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_vertical_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      android:text="I&apos;m pookie jeans" 
      android:textAppearance="?android:attr/textAppearanceSmallInverse" 
      android:textStyle="bold" 
      android:typeface="serif" 
      android:gravity="center" /> 

     <Button 
      android:layout_width="224dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:text="Button 1" 
      android:textSize="25dp" 
      android:textStyle="bold" /> 

    </LinearLayout> 



>**AndroidManifest.xml** 
    <?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.pooks.thebasics" 
     android:versionCode="1" 
     android:versionName="1.0" > 

     <uses-sdk 
      android:minSdkVersion="8" 
      android:targetSdkVersion="17" /> 

     <application 
      android:allowBackup="true" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme" > 
      <activity 
       android:name="com.pooks.thebasics.main" 
       android:label="@string/app_name" > 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
      </activity> 
       <activity 
       android:name="com.pooks.thebasics.menu" 
       android:label="@string/app_name" > 
       <intent-filter> 
        <action android:name="com.pooks.thebasics.MENU" /> 

        <category android:name="android.intent.category.DEFAULT" /> 
       </intent-filter> 
      </activity> 
     </application> 

    </manifest> 

: 여기

의 코드 내 페이지입니다. 그러나 그것은 한순간에 일하고있었습니다. 나는 그것을 모두 합쳐 놓았을 때 충돌이 일어나기 시작했다. 다시 한 번 도움이 될 것입니다.

+3

는, 로그 캣에서 스택 추적을 게시 할 수 있습니다. – Karakuri

+0

대부분의 문제가 해결되었습니다. 나는 당신이 당신의 자바 이름을 대문자로 시작하기를 원한다고 읽었고 그것을 변경했지만 내 매니 페스트 또는 자바 활동에서 변경하지 않았다. 나는 또한 당신이 안드로이드를 정량화하기를 원한다는 것을 읽었다. 그래서 나는 패키지 이름을 꺼내어 ".Menu"또는 ".Main"을 넣었다. 그것은 그것을 고쳤다. 이제 5 초의 수면이 작동하지 않습니다. 도움이 필요 하신가요? – Patrick

+1

"자바 이름이 대문자로 시작되기를 원하지 않습니다." 클래스 이름은 대문자로 시작하지만 클래스 및 필드 이름의 인스턴스에는 소문자로 시작해야합니다. 무엇을 하든지 문자가 아닌 문자를 첫 번째 문자로 사용하여 클래스 나 필드의 이름을 지정하지 마십시오. – MarsAtomic

답변

0

특정 시간 후에 두 번째 활동을 시작하려면 수면을 사용하는 이유는 무엇입니까? 동일한 결과를 얻으려면 Timer을 사용할 수 있습니다. 또한, 의도가 잘못되었습니다. 새로운 활동을 생성하려고하는 부모 컨텍스트를 제공해야합니다.

이 시도 : 당신이 충돌이있는 경우

new Timer().schedule(new TimerTask() { 

    @Override 
    public void run() { 
     // TODO Auto-generated method stub 
     Intent menuIntent = new Intent(Main.this, menu.class); 
     startActivity(menuIntent); 
    } 
}, 5000); 
0

내 실수를 발견했습니다. 나는 여러 가지 불일치가 있었다. 내가 불일치를 고쳤을 때 나는 그것을 얻었습니다. 둘째, 나는 내가하고있는 것을 기억했다. 첫 번째 활동은 앱이 시작될 때 시작됩니다. 처음으로 열어 본 다음 홈 버튼을 클릭하면 앱이 백그라운드에서 열려 있습니다. 논리 오류였습니다. 고맙게도 구문 오류는 고통스런 일입니다!

관련 문제