Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 2    Views: 1134

immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
11/12/16 01:16 PM (7 years ago)

Android- I am trying to override onBackPressed() for a couple of plugins

Having a little trouble configuring my onBackPressed() method. From some pages Id like to have the default back button return to the homepage. The current Override i found in BT_activity_host //@Override public void onBackPressed() { super.onBackPressed(); BT_debugger.showIt(activityName + ":onBackPressed"); //currentFragment must exist... if(currentFragment != null){ /* use reflection to trigger a handleBackButton method in the current plugin...not all plugins implement this method...but can as needed. In most cases the handleBackButton method should "go back" by popping the current fragment off the stack. In other cases it may do something all together different. */ java.lang.reflect.Method backMethod = null; try{ backMethod = currentFragment.getClass().getMethod("handleBackButton"); }catch(SecurityException e){ BT_debugger.showIt(activityName + ":onBackPressed. EXCEPTION (0): " + e.toString()); }catch(NoSuchMethodException e){ BT_debugger.showIt(activityName + ":onBackPressed. Current fragment does not have an "onBackPressed" method implemented"); } //fire the handleBackButton method if we found it... if(backMethod != null){ try{ backMethod.invoke(currentFragment); }catch(Exception e){ BT_debugger.showIt(activityName + ":onBackPressed. EXCEPTION (1): " + e.toString()); } } } } when i try add the following code to the existing code i get cannot resolve symbol 'screenData' and 'loadScreenWithItemId' if (screenData.getItemId().equals("6D7714F17FA8EE3042DE5E4") || screenData.getItemId().equals("6F3CFE968F3B3388997039C")) { loadScreenWithItemId("E830EB81EC9AF19C9B0E2D4"); } I know both of these methods are from different files and am struggling to reference them from this one. I've tried BT_fragment.loadScreenWithItemId but as its not static this works neither and cannot make static as it then causes a heap of other errors. Just wondering how can I get around this. thanks
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
11/16/16 06:12 PM (7 years ago)
Usually when you get that error it means you didn't initialize the variables it's complaining about. Are you putting this code in the plugins under onCreateView? I'm thinking you haven't put this in the plugin because it wouldn't complain about loadScreenWithItemId class because it's inherited from the Bt_fragment class and all plugins should extend that class. you can't just use the screen data variable. Look in other classes and it will show you how to get screen data for that specific screen . I'm not at a computer right now so can't look.
 
immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
like
11/16/16 09:21 PM (7 years ago)
I first tried adding the code to my plugins under oncreateview, which didn't return the cannot resolve symbol errors but instead i got "Method does not Override method from its superclass". Id say because onbackpressed() is already overridden in BT_activity_host.java Thats why I've tried adding my code to the existing onbackpressed() in activity_host. Which then returns the other errors. I use the loadScreenWithItemId and screenData in plugins already so i know they work. and I've solved the problem now anyways. under onbackpressed() in activity_host i changed if(backMethod != null){ try{ backMethod.invoke(currentFragment); }catch(Exception e){ BT_debugger.showIt(activityName + ":onBackPressed. EXCEPTION (1): " + e.toString()); } to this if(backMethod != null){ try{ showAppHomeScreen(); }catch(Exception e){ BT_debugger.showIt(activityName + ":onBackPressed. EXCEPTION (1): " + e.toString()); } Now every plugin returns to home page when back pressed.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.