[ https://issues.apache.org/jira/browse/CB-1062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13455647#comment-13455647 ]
Andreas Sommer commented on CB-1062: ------------------------------------ Here's some example code. I'm using ActionBarSherlock on my main activity to provide a tab bar, and have a Cordova plugin that lets JavaScript code register a callback for tab selection changes. This might be a specific case - you can decide if it makes sense to replace the singleton pattern by a getPluginInstance method. {code:java} import com.actionbarsherlock.app.ActionBar; import my.TabBarBridgePlugin; ... public final class MainActivity extends DroidGap implements ActionBar.TabListener { @Override public void onTabSelected(Tab tab, android.support.v4.app.FragmentTransaction ft) { // Plugin not initialized yet at app startup if(TabBarBridgePlugin.instance != null) TabBarBridgePlugin.instance.triggerTabSelectedEvent((String)tab.getTag()); } ----- public class TabBarBridgePlugin extends Plugin { public String callback; public static TabBarBridgePlugin instance; public TabBarBridgePlugin(){instance=this;} public PluginResult execute(String action, JSONArray args, String callbackId) { if(action.equals("setTabSelectedListener")) { this.callback = callbackId; if(args.length() != 0) throw new AssertionError("setTabSelectedListener takes no arguments"); PluginResult res = new PluginResult(PluginResult.Status.NO_RESULT); res.setKeepCallback(true); return res; } else { return new PluginResult(PluginResult.Status.INVALID_ACTION); } } public void triggerTabSelectedEvent(String tabName) { PluginResult res = new PluginResult(PluginResult.Status.OK, tabName); res.setKeepCallback(true); this.success(res, callback); } } {code} > Way to get instance of a plugin via PluginManager > ------------------------------------------------- > > Key: CB-1062 > URL: https://issues.apache.org/jira/browse/CB-1062 > Project: Apache Cordova > Issue Type: Wish > Components: Android > Reporter: Andreas Sommer > Assignee: Joe Bowser > Fix For: 2.2.0 > > > PluginManager.getPlugin should be made public so that a plugin's instance can > be retrieved in Java code. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira