Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Feb 15, 2017 at 02:18 PM by Raitosaur for the following reason:

Other

Solution was found during moderation process, though it was an alternative to the requested solution. But, if it works it works i suppose.

avatar image
0
Question by Raitosaur · Feb 17, 2017 at 09:12 AM · androidvuforiajava

Android, Vuforia and mUnityPlayer.exit()

After porting a basic Vuforia application over to Android, and allowing me to change to it as a new activity i started working on embedding it of sorts into an activity. Here i found the problem that turning the phone would call onDestroy, and also the unityplayers mUnityPlayer.quit().

In an attempt to work around it, i tried to put it in its own fragment, allowing the fragment to be closed and recreated, but to no avail. Seems like mUnityPlayer.quit() closes the application completely.

Is there a good way to prevent the unityplayer from closing the application whenever i change orientation without using android:config or locking the orientation of the application?

Edit: By dropping fragments and putting it all into the mainActivity it gave the same effect as i'd hope. Solution was found here: http://stackoverflow.com/questions/23467994/errors-managing-the-unityplayer-lifecycle-in-a-native-android-application?noredirect=1&lq=1

Still, shame you can't make it work with a fragment, meaning it has to be the main part of the activity.

MainActivity:

     private Button startUnityActivity;
     private Button startUnityEmbedded;
 
     @Override protected void onCreate (Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.mainactivity);
 
         if (savedInstanceState == null)
         {
             Fragment newFragment = new UnityFragment();
             FragmentTransaction ft = getFragmentManager().beginTransaction();
             ft.add(R.id.UnityFragment, newFragment).commit();
         }
     }

UnityFragment:

 public class UnityFragment extends Fragment
 {
     protected UnityPlayer mUnityPlayer;
     private FrameLayout unityFrame;
 
     public UnityFragment() {}
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
     {
         View view = inflater.inflate(R.layout.unityfragment, container, false);
         mUnityPlayer = new UnityPlayer(getActivity());
 
         this.unityFrame = (FrameLayout) view.findViewById(R.id.UnityFragment);
         this.unityFrame.addView(mUnityPlayer.getView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
 
         mUnityPlayer.requestFocus();
         // mUnityPlayer.windowFocusChanged(true); // Fix for blackscreen unity player.
 
         return view;
     }
 
     // Quit Unity
     @Override
     public void onDestroy() {
         mUnityPlayer.quit();
         super.onDestroy();
     }
 
     // Pause Unity
     @Override
     public void onPause() {
         super.onPause();
         mUnityPlayer.pause();
     }
 
     // Resume Unity
     @Override
     public void onResume() {
         super.onResume();
         mUnityPlayer.resume();
     }
 }

MainActivity.xml

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 xmlns:tools="http://schemas.android.com/tools"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:background="@android:color/darker_gray"
                 android:id="@+id/MainLayout">
 
     <fragment
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:id="@+id/UnityEmbedded"
         android:layout_above="@+id/FirstButton"
         android:background="@android:color/darker_gray"
         android:name="com.testing.VuforiaImageTracking.UnityFragment"
         tools:layout="@layout/unityfragment">
     </fragment>
 
     <Button
         android:text="Start Unity Activity"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:id="@+id/FirstButton"
         android:layout_above="@+id/SecondButton"/>
 
     <Button
         android:text="Start Unity Embedded"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:id="@+id/SecondButton"
         android:layout_centerInParent="true"
         android:layout_alignParentBottom="true"/>
 
 </RelativeLayout>
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

151 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Failed to recompile android resource files Unity 0 Answers

Create Custom Layout in android studio imported Unity project 0 Answers

How can I use SQLite Database made with android studio in Unity? 0 Answers

How freezing AR Camera when hitting an Object 0 Answers

Callback when vuforia AR camera finishes loading 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges