2011-11-10 140 views
0

我找不到任何適合我的幫助,因此這是啓動活動的特定情況。 我有一個項目中,我有類MrNomAndroid無法啓動從其他活動擴展活動的Android類

public class MrNomGame extends AndroidGame { 

    public Screen getStartScreen() { 
      return new LoadingScreen(this); 
    } 

的AndroidGame類看起來是這樣的:

public abstract class AndroidGame extends Activity implements Game{ 
    /** 
    * @uml.property name="renderView" 
    * @uml.associationEnd inverse="game:ro.lasting.androidgames.framework.impl.AndroidFastRenderView" 
    */ 
    public static AndroidFastRenderView renderView;//we draw to this and it manages the main loop thread 
    /** 
    * @uml.property name="graphics" 
    * @uml.associationEnd 
    */ 
    private Graphics graphics; 
    /** 
    * @uml.property name="audio" 
    * @uml.associationEnd 
    */ 
    private Audio audio; 
    /** 
    * @uml.property name="input" 
    * @uml.associationEnd 
    */ 
    private Input input; 
    /** 
    * @uml.property name="fileIO" 
    * @uml.associationEnd 
    */ 
    private FileIO fileIO; 
    /** 
    * @uml.property name="screen" 
    * @uml.associationEnd 
    */ 
    private Screen screen;//holds the currently active screen 
    /** 
    * @uml.property name="wakeLock" 
    * @uml.associationEnd 
    */ 
    private WakeLock wakeLock;//we use this to keep the screen for dimming 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     /*make activity fullscreen*/ 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
     WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     //setup artificial framebuffer 
     boolean isLandscape = getResources().getConfiguration().orientation == 
     Configuration.ORIENTATION_LANDSCAPE; 

     int frameBufferWidth = isLandscape ? 480 : 480; 
     int frameBufferHeight = isLandscape ? 320 : 320; 
     Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth, 
     frameBufferHeight, Config.RGB_565);//Bitmap instance has an RGB565 color format for not wasting memory and speed up the drawing 
     //Calculate scaleX and scaleY values that SingleTouchHandler 
     // and MultiTouchHandler classes will use to transform the 
     // touch event coordinates to our fixed-coordinate system 
     float scaleX = (float) frameBufferWidth/getWindowManager().getDefaultDisplay().getWidth(); 

     float scaleY = (float) frameBufferHeight/getWindowManager().getDefaultDisplay().getHeight(); 

     //renderView = new AndroidFastRenderView(this, frameBuffer); 
     graphics = new AndroidGraphics(getAssets(), frameBuffer); 
     fileIO = new AndroidFileIO(getAssets()); 
     audio = new AndroidAudio(this); 
     input = new AndroidInput(this, renderView, scaleX, scaleY); 
     screen = getStartScreen(); 

     setContentView(renderView); 
     //if(ro.lasting.androidgames.mrnom.MainMenuScreen.sinvite)setContentView(ro.lasting.androidgames.mrnom.R.layout.invite); 

     PowerManager powerManager = (PowerManager) 
     getSystemService(Context.POWER_SERVICE); 
      wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame"); 

    } 

    public void onResume() { 
     super.onResume(); 
     wakeLock.acquire(); 
     screen.resume(); 
     renderView.resume(); 
    } 

    public void onPause() { 
     super.onPause(); 
     wakeLock.release(); 
     renderView.pause(); 
     screen.pause(); 
     if (isFinishing()) 
      screen.dispose(); 
    } 

    /** 
    * @return 
    * @uml.property name="input" 
    */ 
    public Input getInput() { 
     return input; 
    } 

    /** 
    * @return 
    * @uml.property name="fileIO" 
    */ 
    public FileIO getFileIO() { 
     return fileIO; 
    } 

    /** 
    * @return 
    * @uml.property name="graphics" 
    */ 
    public Graphics getGraphics() { 
     return graphics; 
    } 

    /** 
    * @return 
    * @uml.property name="audio" 
    */ 
    public Audio getAudio() { 
     return audio; 
    } 

    /** 
    * @param screen 
    * @uml.property name="screen" 
    */ 
    public void setScreen(Screen screen) { 
     if (screen == null) 
      throw new IllegalArgumentException("Screen must not be null"); 

     this.screen.pause(); 
     this.screen.dispose(); 
     screen.resume(); 
     screen.update(0); 
     this.screen = screen; 
    } 
    public Screen getCurrentScreen() { 
     return screen; 
    } 
} 

,我也有一個包含下列相應的清單文件:

<activity android:name=".MrNomGame" 
        android:label="@string/app_name" 
        android.screenOrientation="landscape" 
        android:configChanges="keyboard|keyboardHidden|orientation"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

這個應用程序工作得很好。 但是,如果我試圖把它放在另一個應用程序中,我就會關閉它。 我的另一個項目是這樣的:

public class MainActivity extends Activity{ 
    @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.endgame);  

      Intent intent = new Intent(this,MrNomGame.class); 
      //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(intent); 
    } 

與coresponding清單文件:

<activity android:name=".MainActivity" android:theme="@style/ThemeFullScreenNoTitle" 
      android:label="@string/app_name" android:screenOrientation="landscape"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".MrNomGame" android:label="@string/app_name" 
      android.screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation"> 

我希望這個工作,但事實並非如此。我嘗試了一整天,並且無法從我的MainActivity獲得我的第一堂課(MrNomGame)。然而,就我自己的問題的第一部分而言,它本身就很好。對不起這段代碼和一個大問題,但我只是想讓你更容易理解我遇到的這個特定問題。那麼,我如何從我的主要活動開始MrNomGame?謝謝。

+1

什麼是與力關閉記錄的異常? – Jens

+0

您的應用程序意外停止,請再試一次。在日誌貓是一些活動異常。 – Fofole

+0

@Fofole,Jens正在談論logcat ..而不是手機上的信息。 – SERPRO

回答

2
     android:name=".MrNomGame" 

這不會工作,請嘗試使用完全限定的名稱。 Lyk

   android:name="YourPackageName.MrNomGame" 

對不起,如果我完全錯了。

+0

我已經解決了這個問題,但這是一個很好的答案。 – Fofole

1

嘗試更改android.screenOrientationandroid:screenOrientation。這可能不是它,因爲它在1個應用程序中運行,但不是另一個,但它仍是一個錯字。

+0

這不回答我的問題 – Fofole