Search Unity

Android Plugin Example not working

Discussion in 'Android' started by gfxguru, Jul 21, 2015.

  1. gfxguru

    gfxguru

    Joined:
    Jun 5, 2010
    Posts:
    107
    While experimenting with subclassing UnityPlayerActivity i had made a plugin with docs code.

    Code (CSharp):
    1. package com.company.product;
    2.  
    3. import com.unity3d.player.UnityPlayerActivity;
    4.  
    5. import android.os.Bundle;
    6. import android.util.Log;
    7.  
    8. public class OverrideExample extends UnityPlayerActivity {
    9.  
    10.   protected void onCreate(Bundle savedInstanceState) {
    11.  
    12.     // call UnityPlayerActivity.onCreate()
    13.     super.onCreate(savedInstanceState);
    14.  
    15.     // print debug message to logcat
    16.     Log.d("OverrideActivity", "onCreate called!");
    17.   }
    18.  
    19.   public void onBackPressed()
    20.   {
    21.     // instead of calling UnityPlayerActivity.onBackPressed() we just ignore the back button event
    22.     // super.onBackPressed();
    23.   Log.d("MyPluginActivity", "BackbuttonPressed");
    24.   }
    25. }
    As per the code onBackButton should not trigger the normal backbutton response and should print the message in log. But it is not happening, on back button press the message is never displayed. Am i missing something or what is the correct method.

    Please help
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I think that Unity's activity is not propogating the back press to your activity, so you're never seeing it and cannot react to it.