Mike Kwan created CB-3018:
-----------------------------

             Summary: Allow Cordova to be 
                 Key: CB-3018
                 URL: https://issues.apache.org/jira/browse/CB-3018
             Project: Apache Cordova
          Issue Type: Improvement
          Components: Android
    Affects Versions: 2.5.0
            Reporter: Mike Kwan
            Assignee: Joe Bowser


It is difficult to use Cordova when using the Fragment API added in API level 
11 (Android 3.0). A cursory search reveals other developers are having similar 
problems or have created workarounds:
http://stackoverflow.com/questions/13070205/android-phonegap-and-fragments
https://groups.google.com/forum/?fromgroups=#!topic/phonegap/aVvf1bnDavM

A typical usecase for CordovaWebView within Fragments is if an app wants to 
support multiple independent CordovaWebViews within an Activity. With the 
deprecation of TabActivity in 3.0 we are seeing an increasing move to the 
recommended Fragment architecture. The usage of Fragments in standard Android 
apps is significant and I believe it would make sense to allow Cordova to be 
more accessible from this paradigm.

The Android implementation of Cordova is heavily biased towards users who want 
to use CordovaWebView from within an Activity. In comparison, using 
CordovaWebView from within a Fragment can be rather unwieldy.
 - Cordova provides DroidGap which extends Activity and conveniently provides:
    - A standard implementation of CordovaInterface.
    - A standard configuration of the CordovaWebView class (vanilla 
CordovaWebViewClient and CordovaChromeClient)
   When using a Fragment the developer is forced to reimplement this 
boilerplate code (see the workaround provided at 
http://www.infil00p.org/advanced-tutorial-using-cordovawebview-on-android/). 
The configuration of the CordovaWebView itself is trivial in comparison to the 
code that has to be duplicated for CordovaInterface.
 - CordovaPlugin provides a reference to a CordovaInterface which in turn 
provides access to the containing Activity. As far as I am aware it is not 
possible to get access to the associated Fragment without storing a Fragment to 
CordovaWebView mapping within the Activity: 
http://stackoverflow.com/questions/13070205/android-phonegap-and-fragments

Rather than working around Cordova it would be really great if the library 
added support for Fragments. One solution I suggest is:
 - Extract the implementation of CordovaInterface out from DroidGap. 
CordovaImpl can then be instantiated and reused for Fragments.
 - Refactoring CordovaInterface properly to work with Fragments rather than 
Activity will require a substantial change - I need to look deeper into the 
code before commenting here. This issue presents a major barrier to using 
Cordova to its full capacity with Fragments.

--
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

Reply via email to