- Home /
Android Project Error when using getApplication() for UnityPlayer ?
Hi ,in my android project ,i use "getApplication() " to init UnityPlayer ,like this:
// Setup activity layout
@Override protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGB_565);
mUnityPlayer = new UnityPlayer(getApplication());
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
But it crash .and the log is quite simple :**
dalvikvm(14086): Trying to load lib /data/app-lib/com.lioncat.test-2/libmain.so 0x437c7910
dalvikvm(14086): Added shared lib /data/app-lib/com.lioncat.test-2/libmain.so 0x437c7910
libc(14086): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 14086 (om.lioncat.test)
For some reason ,i have to use "getapplication" for unityplayer's context instead of "Activity" . Any help or suggestion?
For future posts, please include code as text formatted with the 101/010 button rather than an image.
Answer by liortal · Oct 23, 2014 at 06:12 AM
Usually you subclass Unity's activity and create your own activity.
You don't need to create the UnityPlayer, it is already created for you and your custom activity is assigned to its static currentActivity field.
See this link: http://docs.unity3d.com/Manual/PluginsForAndroid.html
Specifically, under "Extending the UnityPlayerActivity Java Code"
Your answer
Follow this Question
Related Questions
lighter and faster application (android) - advices 1 Answer
Android Native Screenshot function creats black Image 1 Answer
Do not allow the android screen off. 1 Answer
Path for Assets/Textures folder File in Android 2 Answers
Application.isMobile() equivalent of Application.isWebPlayer() ? 2 Answers