2013-08-25 99 views
0

我有一個意圖的問題。 它在開始活動時突然崩潰。 這裏是第一個活動:意圖崩潰在開始活動

package com.logio.bullsandcows; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
import android.view.Menu; 

public class StartingActivity extends Activity{ 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.start); 
     Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      public void run() { 
       Intent intent = new Intent(StartingActivity.this, MainActivity.class); 
       intent.putExtra("ex", true); 
       startActivity(intent); 
      } 
     }, 2000); 
    } 
} 

這是第二個:

package com.logio.bullsandcows; 

import android.app.*; 
import android.media.AudioManager; 
import android.media.SoundPool; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 
import android.content.Intent; 
import android.content.res.AssetFileDescriptor; 
import android.content.res.AssetManager; 

import java.io.IOException; 
import java.util.*; 

public class MainActivity extends Activity 
{ 
    SoundPool mSP; 
    AssetManager assets; 
    int butpress1, butpress2, butpress3; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.mainmenu); 

     mSP = new SoundPool(3, AudioManager.STREAM_MUSIC, 0); 
     assets = getAssets(); 

     butpress1 = loadSound("1378.mp3"); 
     butpress2 = loadSound("1380.mp3"); 
     butpress3 = loadSound("1382.mp3"); 

    Button buttonnewgame = (Button) findViewById(R.id.buttonnewgame); 
    Button buttonabout = (Button) findViewById(R.id.buttonabout); 
    Button buttonhelp = (Button) findViewById(R.id.buttonhelp); 


    buttonnewgame.setOnClickListener(new OnClickListener(){ 
     public void onClick(View v){ 
       playSound(butpress1); 
      switch(v.getId()){ 
        case R.id.buttonnewgame: 
        Intent intent6 = new Intent(MainActivity.this, GameMenu.class); 
        startActivity(intent6); 
        break; 
       } 
    } 
    }); 

     buttonabout.setOnClickListener(new OnClickListener(){ 
     public void onClick(View v){ 
      playSound(butpress2); 
       switch(v.getId()){ 
        case R.id.buttonabout: 
       Intent intent = new Intent(MainActivity.this, AboutActivity.class); 
       startActivity(intent); 
       break; 
       } 
    } 
    }); 

    buttonhelp.setOnClickListener(new OnClickListener(){ 
    public void onClick(View v){ 
     playSound(butpress3); 
      switch(v.getId()){ 
      case R.id.buttonhelp: 
      Intent intent = new Intent(MainActivity.this, HelpActivity.class); 
      startActivity(intent); 
      break; 
     } 
     } 
}); 

if (getIntent().getBooleanExtra("ex", false)){ 
    finish(); 
    return; 
} 
} 

    private int loadSound(String fileName){ 
    AssetFileDescriptor afd = null; 
    try{ 
     afd = assets.openFd(fileName); 
    } catch (IOException e){ 
     e.printStackTrace(); 
     Toast.makeText(this, "Oops! '"+fileName+"' not found!", Toast.LENGTH_SHORT).show(); 
     return -1; 
    } 
return mSP.load(afd, 1); 
    } 

    protected void playSound(int sound){ 
     if(sound>0) 
      mSP.play(sound, 1, 1, 1, 0, 1); 
    } 


protected void shuffleArray(String[] specArray) { 
    // TODO Auto-generated method stub 
    Random rnd = new Random(); 
    for(int i = specArray.length-1; i>=0; i--) 
    { 
     int index = rnd.nextInt(i+1); 
     String a= specArray[index]; 
     specArray[index] = specArray[i]; 
     specArray[i]=a; 
    } 
} 
    } 

這是我表現的一部分:

<activity 
    android:name="com.logio.bullsandcows.MainActivity" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
    android:label="@string/app_name" 
    android:screenOrientation="portrait"> 
     <intent-filter> 
     <action android:name="android.intent.action.MAINACTIVITY" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter>    
</activity> 

<activity 
    android:name="com.logio.bullsandcows.StartingActivity" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
    android:label="@string/app_name" 
    android:screenOrientation="portrait"> 
<intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 

什麼我可以改變?它始終在startActivity(intent)上崩潰,即使這兩個活動都是在manifest中聲明的。

+2

可能發佈stacktrace可以幫助 – Blackbelt

+0

我該怎麼做 – Aakurb

+0

從logcat複製它? – Blackbelt

回答

0

我解決了這個問題的另一種方式。 當我啓動第二個活動時,我立即啓動第一個活動2秒鐘,然後銷燬它。

1

更新

if(getIntent().getBooleanExtra("ex", false)){ 
    Log.e("Hi", "It was false");  
} else { 
    Log.e("Hi", "It was true"); 
} 
} 

試試這個,因爲你正在整理活動,如果是假

更新

<activity 
     android:name="com.logio.bullsandcows.MainActivity" 
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait"> 
      <intent-filter> 
      <action android:name="android.intent.action.MAINACTIVITY" /> 
<category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter>    
    </activity> 
+0

致命的信號11(SIGSEGV)在0x00000000(代碼= 1),線程20666 ... – Aakurb

+0

線程20666(io.bullsandcows) – Aakurb

+0

如果我啓動mainactivity爲主,它工作正常,沒有錯誤 – Aakurb