incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Sommer (JIRA)" <>
Subject [jira] [Commented] (CB-1062) Way to get instance of a plugin via PluginManager
Date Fri, 14 Sep 2012 07:49:09 GMT


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.

import my.TabBarBridgePlugin;

public final class MainActivity extends DroidGap implements ActionBar.TabListener
    public void onTabSelected(Tab tab, ft)
        // Plugin not initialized yet at app startup
        if(TabBarBridgePlugin.instance != null)

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)
            this.callback = callbackId;

            if(args.length() != 0)
                throw new AssertionError("setTabSelectedListener takes no arguments");

            PluginResult res = new PluginResult(PluginResult.Status.NO_RESULT);
            return res;
            return new PluginResult(PluginResult.Status.INVALID_ACTION);

    public void triggerTabSelectedEvent(String tabName)
        PluginResult res = new PluginResult(PluginResult.Status.OK, tabName);
        this.success(res, callback);
> Way to get instance of a plugin via PluginManager
> -------------------------------------------------
>                 Key: CB-1062
>                 URL:
>             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:

View raw message