• 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 /
avatar image
0
Question by Gianluca88 · Apr 29, 2015 at 09:34 AM · activity

Problem to close Unity Project integrate in Android Activity

Hi All, I follow this guide for integrate one Unity project into an Android Activity. Thanks to a Button I start this Activity and all run very well, I am able to send message from Android to Unity, very cool. The problem is when I try to close this activity using onBackPressed Event. The activity is close but when I try to re-open it I have just a black screen and the unity project isn't create, my Logcat send me this error:

 04-29 11:23:36.305: E/ActivityThread(22316): Activity com.example.footmoov_prove.Avatar has leaked IntentReceiver com.unity3d.player.UnityPlayer$3@41e15558 that was originally registered here. Are you missing a call to unregisterReceiver()?
 04-29 11:23:36.305: E/ActivityThread(22316): android.app.IntentReceiverLeaked: Activity com.example.footmoov_prove.Avatar has leaked IntentReceiver com.unity3d.player.UnityPlayer$3@41e15558 that was originally registered here. Are you missing a call to unregisterReceiver()?
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:792)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:593)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1254)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1241)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1235)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:372)
 04-29 11:23:36.305: E/ActivityThread(22316):     at com.unity3d.player.UnityPlayer.<init>(Unknown Source)
 04-29 11:23:36.305: E/ActivityThread(22316):     at com.example.footmoov_prove.Avatar.onCreate(Avatar.java:34)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.Activity.performCreate(Activity.java:5206)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.os.Handler.dispatchMessage(Handler.java:99)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.os.Looper.loop(Looper.java:137)
 04-29 11:23:36.305: E/ActivityThread(22316):     at android.app.ActivityThread.main(ActivityThread.java:4898)
 04-29 11:23:36.305: E/ActivityThread(22316):     at java.lang.reflect.Method.invokeNative(Native Method)
 04-29 11:23:36.305: E/ActivityThread(22316):     at java.lang.reflect.Method.invoke(Method.java:511)
 04-29 11:23:36.305: E/ActivityThread(22316):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
 04-29 11:23:36.305: E/ActivityThread(22316):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
 04-29 11:23:36.305: E/ActivityThread(22316):     at dalvik.system.NativeStart.main(Native Method)
 

My Activity code is:

 @Override
     protected void onCreate(Bundle savedInstanceState){
         super.onCreate(savedInstanceState);
         setContentView(R.layout.avatar);
         m_UnityPlayer = new UnityPlayer(this);
         int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
         boolean trueColor8888 = false;
         m_UnityPlayer.init(glesMode, trueColor8888);
         
         FrameLayout layout = (FrameLayout) findViewById(R.id.framelayout_avatar);
         LayoutParams lp = new LayoutParams (LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
         layout.addView(m_UnityPlayer.getView(), 0, lp);
 
     }

 

 @Override
     public void onWindowFocusChanged(boolean hasFocus){
         super.onWindowFocusChanged(hasFocus);
         m_UnityPlayer.windowFocusChanged(hasFocus);
     }

 @Override
     public void onBackPressed(){
         LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
         super.onBackPressed();
     }


Other code in the Activity is not important

Comment
Add comment · Show 1
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
avatar image gts101 · Jun 02, 2015 at 08:12 AM 0
Share

hi, did you ever find an answer to this?

I have the exact same problem. I posted a question on Stack Overflow yesterday but so far ive got no useful answers.

http://stackoverflow.com/questions/30579712/android-embedding-unity3d-scene-in-activity-need-to-unregister-receiver

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gts101 · Jun 04, 2015 at 08:19 AM

I finally found an answer to this... just follow the stackoverflow link above and read my answer!

Comment
Add comment · Share
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

How to extend Activity (Android)? 1 Answer

Android Custom Activity -1 Answers

how to integrate 2 unity activity within 1 android app 0 Answers

Android and Unity - creating a transparent Activity 1 Answer

Calling an AppCompatActivity, You need to use a Theme.AppCompat theme (or descendant) with this activity 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