Home > Mobile >  Android embedded Unity MainActivity to UnityActivity finish will crash error again
Android embedded Unity MainActivity to UnityActivity finish will crash error again

Time:10-03

I built a simple unity project, exported as simple, not directly with the android project, then create a new android project, unity will export the resources of copy one by one go in, and then to jump in the mainActivity unityActivity, but every time I finish the current unityActivity would crash, here is my android code, the great god help look at this is why, very grateful!

Manifests:
 & lt; ? The XML version="1.0" encoding="utf-8"?> 
Package="com. Cain. Unitytest" & gt;

Android: smallScreens="true"
Android: normalScreens="true"
Android: largeScreens="true"
Android: xlargeScreens="true"
Android: anyDensity="true"/& gt;


The android: name="tool. MyApplication"
Android: allowBackup="true"
The android: icon="@ mipmap/ic_launcher"
Android: label="@ string/app_name"
Android: supportsRtl="true"
Android: theme="@ style/AppTheme" & gt;
Android: name="activity. The MainActivity"
Android: screenOrientation="portrait"
Android: launchMode="singleTask" & gt;



Android: screenOrientation="portrait"
Android: configChanges="MCC | newsun focus | locale | touchscreen | the rid_device_info_keyboard | keyboardHidden | navigation | orientation | screenLayout | uiMode | screenSize | smallestScreenSize | fontScale" & gt;
<meta - data android: name="unityplayer UnityActivity" android: value="https://bbs.csdn.net/topics/true"/& gt;
<meta - data android: name="unityplayer ForwardNativeEventsToDalvik" android: value="https://bbs.csdn.net/topics/false"/& gt;






UnityPlayerActivity:
 package com. Cain. Unitytest. Activity; 

The import com. Cain. Unitytest. R;
The import com. Cain. Unitytest. Inject. ContentView;
The import com. Cain. Unitytest. Inject. ViewInject;
The import com. Unity3d. Player. *;

The import android. Content. Res. The Configuration;
The import android. OS. Bundle;
The import android. View. MotionEvent;
The import android. View. The view;
The import android. Widget. LinearLayout;
The import android. Widget. Toast;

@ SuppressWarnings (" unused ")
@ ContentView (R.l ayout. Activity_unity)
Public class UnityPlayerActivity extends BaseActivity {
Private static final String TAG=UnityPlayerActivity. Class. GetSimpleName ();

Protected UnityPlayer mUnityPlayer;//don 't change the name of this variable; Referenced from native code

@ ViewInject (R.i d.u nity_test_view)
Private LinearLayout unityPanel;

//Setup the activity layout
@ Override protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MUnityPlayer=new UnityPlayer (this);

UnityPanel. AddView (mUnityPlayer);
}

/* *
* change the background color, the unity function called
* @ param v launch component
*/
Public void changeBackgroundColor (View v) {
UnityPlayer. UnitySendMessage (" AndroidInterface ChangeCameraBackground ", ""," # fafafa ");
}

/* *
* show toast, is called the unity
* @ param message toast content
*/
Public void showToast (final String message) {
RunOnUiThread (new Runnable () {
@ Override
Public void the run () {
Toast. MakeText (UnityPlayerActivity. This, the message, Toast. LENGTH_SHORT), show ();
}
});
}

/* *
* return to last page
*/
@ Override
Public void onBackPressed () {
//super. OnBackPressed ();
//UnityPlayer. UnitySendMessage (" AndroidInterface "and" Finish ", "");
//mUnityPlayer. Quit ();
finish();
}

//the Quit Unity
@ Override
Protected void onDestroy () {
MUnityPlayer. Quit ();
super.onDestroy();
}

//Pause Unity
@ Override
Protected void onPause () {
Super. OnPause ();
MUnityPlayer. Pause ();
}

//Resume Unity
@ Override
Protected void onResume () {
Super. OnResume ();
MUnityPlayer. Resume ();
}

//This ensures the layout will be correct.
@ Override
Public void onConfigurationChanged (Configuration newConfig) {
Super. OnConfigurationChanged (newConfig);
MUnityPlayer. ConfigurationChanged (newConfig);
}

//Notify the Unity of the focus change.
@ Override
Public void onWindowFocusChanged (Boolean hasFocus) {
Super. OnWindowFocusChanged (hasFocus);
MUnityPlayer. WindowFocusChanged (hasFocus);
}

@ Override
Public Boolean onTouchEvent (MotionEvent event) {
Return mUnityPlayer. InjectEvent (event);
}
}


Crash every time is at the bottom of the error, and each has the following error:
Start the unity page:
7-21 15:54:55. 810, 331-917/? nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related