title: Back Button Support On Android for Cocos2d v3.x via Apportable
body: <p>As described in <a href="http://docs.apportable.com/uikit-extensions" rel="nofollow">Apportable Doc</a>, I have created a subclass of <code>UIResponder</code> named <code>AndroidButtonManager</code> to have support for hardware button tap events (Back, Home button tap) in my current cocos2d-iPhone v3.1 project. Here are the codes of interface and implementation files</p>
  
  <pre><code>AndroidButtonManager.h
  
  #import &lt;Foundation/Foundation.h&gt;
  #import "cocos2d.h"
  
  @interface AndroidButtonManager :UIResponder&lt;UIApplicationDelegate&gt;{
  
  }
  +(instancetype) sharedManager;
  @end
  </code></pre>
  
  <p>and <code>AndroidButtonManager.m</code></p>
  
  <pre><code>#import "AndroidButtonManager.h"
  
  
  @implementation AndroidButtonManager
  +(instancetype)sharedManager
  {
      static AndroidButtonManager* sharedManager;
      static dispatch_once_t onceToken;
      dispatch_once(&amp;onceToken, ^{
          sharedManager = [[self alloc]init];
      });
      return sharedManager;
  }
  -(instancetype)init{
      if (self = [super init]) {
          [self canBecomeFirstResponder];
      }
  
      return self;
  }
  
  #ifdef ANDROID
  // ----------------------------------------------------------------
  //          OVER RIDING PARENT CLASS METHOD
  // ----------------------------------------------------------------
  -(BOOL)canBecomeFirstResponder
  {
      [[AlertManager sharedManager] showAlertWithHeading:@"canBecomeFirstResponder" andMessage:@"AndroidButtonManager"];
      return YES;
  }
  
  - (void)buttonUpWithEvent:(UIEvent *)event
  {
      [[AlertManager sharedManager] showAlertWithHeading:@"buttonUpWithEvent" andMessage:@""];
      switch (event.buttonCode)
      {
          case UIEventButtonCodeBack:
              [[AlertManager sharedManager] showAlertWithHeading:@"Back Button" andMessage:@"Home Button touched , going to transit to Menu Layer"];
              break;
          case UIEventButtonCodeMenu:{
              [[AlertManager sharedManager] showAlertWithHeading:@"Home Button" andMessage:@"Home Button touched , going to transit to Menu Layer"];
              break;
          }
          default:
              break;
      }
  }
  
  #endif
  @end
  </code></pre>
  
  <p>And I am creating the shared manager in AppDelegate's <code>-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code> by</p>
  
  <pre><code>#ifdef ANDROID
      [AndroidButtonManager sharedManager];
  #endif
  </code></pre>
  
  <p>I am getting alert from <code>[[AlertManager sharedManager] showAlertWithHeading:@"canBecomeFirstResponder" andMessage:@"AndroidButtonManager"];</code>, but the alert from <code>[[AlertManager sharedManager] showAlertWithHeading:@"buttonUpWithEvent" andMessage:@""];</code> never appears as <code>- (void)buttonUpWithEvent:(UIEvent *)event</code> is never called.</p>
  
  <p>I have tried implementing this in <code>AppDelegate.m</code> as specified in <a href="https://groups.google.com/forum/#!msg/apportable-discuss/992hX9vEdTw/oTdTnVYyir0J" rel="nofollow">Apportable's Google Group</a>.Both are not working.
  Is there any example project implementing back button support in Android in Cocos2d-v3.x?</p>
  
  <p>Thanks in advance.</p>