Android: Fixed bug in AndroidHarness if appClass can not be found

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7778 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent e44d581fea
commit c58f429543
  1. 41
      engine/src/android/com/jme3/app/AndroidHarness.java

@ -7,8 +7,11 @@ import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.TextView;
import com.jme3.app.Application; import com.jme3.app.Application;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
@ -83,26 +86,34 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
AndroidInput input = new AndroidInput(this); AndroidInput input = new AndroidInput(this);
// Create application instance // Create application instance
try{ try
{
app = null;
view = null;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass); Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);
app = clazz.newInstance(); app = clazz.newInstance();
}catch (Exception ex){
app.setSettings(settings);
app.start();
ctx = (OGLESContext) app.getContext();
view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
setContentView(view);
}
catch (Exception ex)
{
handleError("Class " + appClass + " init failed", ex); handleError("Class " + appClass + " init failed", ex);
setContentView(new TextView(this));
} }
app.setSettings(settings);
app.start();
ctx = (OGLESContext) app.getContext();
view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
setContentView(view);
} }
@Override @Override
protected void onRestart(){ protected void onRestart(){
super.onRestart(); super.onRestart();
app.restart(); if (app != null)
app.restart();
logger.info("onRestart"); logger.info("onRestart");
} }
@ -116,14 +127,16 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
view.onResume(); if (view != null)
view.onResume();
logger.info("onResume"); logger.info("onResume");
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
view.onPause(); if (view != null)
view.onPause();
logger.info("onPause"); logger.info("onPause");
} }
@ -135,7 +148,8 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
@Override @Override
protected void onDestroy(){ protected void onDestroy(){
app.stop(true); if (app != null)
app.stop(true);
super.onDestroy(); super.onDestroy();
logger.info("onDestroy"); logger.info("onDestroy");
} }
@ -193,7 +207,8 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
{ {
if (whichButton != -2) if (whichButton != -2)
{ {
app.stop(true); if (app != null)
app.stop(true);
this.finish(); this.finish();
} }
} }

Loading…
Cancel
Save