You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by Joe Bowser <bo...@gmail.com> on 2012/11/29 00:48:24 UTC

[Android] Refactoring in CordovaActivity

Hey

A while ago I did an experiment where I allowed users to restore their
state in the case that Cordova  gets killed.  This seemed like a good
idea except that I couldn't test it because the Camera requires that
you have background processes running.  That being said, I think that
the code is an improvement and should be put into the next release,
namely so we can throw our users a bone if they want to try restoring
state themselves.

Here's the branch here:

https://github.com/infil00p/cordova-android/commits/CordovaActivity

What do people think?

Joe

Re: [Android] Refactoring in CordovaActivity

Posted by Andrew Grieve <ag...@chromium.org>.
I'm in favour of adding it in, but I think we should hold off until after
this release. We should also think more about how to pass the plugin result
back to the app e.g. via a JS launch arg?


On Wed, Nov 28, 2012 at 7:34 PM, Joe Bowser <bo...@gmail.com> wrote:

> Hey
>
> Yes, the camera is still an issue.  There are two approaches to
> getting around this issue.  One of which is to allow users to restore
> the state that we save for them.  I've added this ability in Cordova
> for the most part, but the problem with the tests is that I never had
> a problem with my camera crashing.  The other is to use a camera
> plugin.
>
> The code to restore state can't actually go into DroidGap in this
> release because we have way too many methods that we have to preserve
> for some reason or another.  We desperately need to refactor DroidGap
> and decide what should be supported and what should go away, and I
> think that should be a big part of 2.4.0.
>
> What this code does is allow for this to be done in the activity
> that's being extended:
>
>
> public class cordovaExample extends DroidGap
> {
>
>     @Override
>     public void onCreate(Bundle savedInstanceState)
>     {
>         super.onCreate(savedInstanceState);
>         super.setBooleanProperty("keepRunning", false);
>
>         super.init();
>
>         if(savedInstanceState != null)
>         {
>             Log.d("Test Application", "Restoring the state");
>             this.appView.restoreState(savedInstanceState);
>         }
>         else
>         {
>             super.loadUrl("file:///android_asset/www/index.html");
>         }
>     }
>
>
>     protected void onSaveInstanceState(Bundle outState)
>     {
>         super.onSaveInstanceState(outState);
>         this.appView.saveState(outState);
>     }
> }
>
> It's not an insane amount of code, and since people are already
> hacking the Java classes anyway, it'd be good to give some people some
> tools to get around this problem.  It's open source, and people
> already have the ability to shoot their faces off, so I'm not
> concerned about them shooting their feet.
>
>
> On Wed, Nov 28, 2012 at 4:22 PM, Lorin Beer <lo...@gmail.com>
> wrote:
> > Hey Joe,
> >
> > is the Camera still an issue for state restoration?  What are the
> > limitations of using this feature?
> >
> > I think the ability to restore state is awesome to have, and would be
> > appreciated, but depending on the limitations I'm concerned this would be
> > like handing users a loaded gun that only points at feet.
> >
> > - Lorin
> >
> > On Wed, Nov 28, 2012 at 3:48 PM, Joe Bowser <bo...@gmail.com> wrote:
> >
> >> Hey
> >>
> >> A while ago I did an experiment where I allowed users to restore their
> >> state in the case that Cordova  gets killed.  This seemed like a good
> >> idea except that I couldn't test it because the Camera requires that
> >> you have background processes running.  That being said, I think that
> >> the code is an improvement and should be put into the next release,
> >> namely so we can throw our users a bone if they want to try restoring
> >> state themselves.
> >>
> >> Here's the branch here:
> >>
> >> https://github.com/infil00p/cordova-android/commits/CordovaActivity
> >>
> >> What do people think?
> >>
> >> Joe
> >>
>

Re: [Android] Refactoring in CordovaActivity

Posted by Joe Bowser <bo...@gmail.com>.
Hey

Yes, the camera is still an issue.  There are two approaches to
getting around this issue.  One of which is to allow users to restore
the state that we save for them.  I've added this ability in Cordova
for the most part, but the problem with the tests is that I never had
a problem with my camera crashing.  The other is to use a camera
plugin.

The code to restore state can't actually go into DroidGap in this
release because we have way too many methods that we have to preserve
for some reason or another.  We desperately need to refactor DroidGap
and decide what should be supported and what should go away, and I
think that should be a big part of 2.4.0.

What this code does is allow for this to be done in the activity
that's being extended:


public class cordovaExample extends DroidGap
{

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.setBooleanProperty("keepRunning", false);

        super.init();

        if(savedInstanceState != null)
        {
            Log.d("Test Application", "Restoring the state");
            this.appView.restoreState(savedInstanceState);
        }
        else
        {
            super.loadUrl("file:///android_asset/www/index.html");
        }
    }


    protected void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        this.appView.saveState(outState);
    }
}

It's not an insane amount of code, and since people are already
hacking the Java classes anyway, it'd be good to give some people some
tools to get around this problem.  It's open source, and people
already have the ability to shoot their faces off, so I'm not
concerned about them shooting their feet.


On Wed, Nov 28, 2012 at 4:22 PM, Lorin Beer <lo...@gmail.com> wrote:
> Hey Joe,
>
> is the Camera still an issue for state restoration?  What are the
> limitations of using this feature?
>
> I think the ability to restore state is awesome to have, and would be
> appreciated, but depending on the limitations I'm concerned this would be
> like handing users a loaded gun that only points at feet.
>
> - Lorin
>
> On Wed, Nov 28, 2012 at 3:48 PM, Joe Bowser <bo...@gmail.com> wrote:
>
>> Hey
>>
>> A while ago I did an experiment where I allowed users to restore their
>> state in the case that Cordova  gets killed.  This seemed like a good
>> idea except that I couldn't test it because the Camera requires that
>> you have background processes running.  That being said, I think that
>> the code is an improvement and should be put into the next release,
>> namely so we can throw our users a bone if they want to try restoring
>> state themselves.
>>
>> Here's the branch here:
>>
>> https://github.com/infil00p/cordova-android/commits/CordovaActivity
>>
>> What do people think?
>>
>> Joe
>>

Re: [Android] Refactoring in CordovaActivity

Posted by Lorin Beer <lo...@gmail.com>.
Hey Joe,

is the Camera still an issue for state restoration?  What are the
limitations of using this feature?

I think the ability to restore state is awesome to have, and would be
appreciated, but depending on the limitations I'm concerned this would be
like handing users a loaded gun that only points at feet.

- Lorin

On Wed, Nov 28, 2012 at 3:48 PM, Joe Bowser <bo...@gmail.com> wrote:

> Hey
>
> A while ago I did an experiment where I allowed users to restore their
> state in the case that Cordova  gets killed.  This seemed like a good
> idea except that I couldn't test it because the Camera requires that
> you have background processes running.  That being said, I think that
> the code is an improvement and should be put into the next release,
> namely so we can throw our users a bone if they want to try restoring
> state themselves.
>
> Here's the branch here:
>
> https://github.com/infil00p/cordova-android/commits/CordovaActivity
>
> What do people think?
>
> Joe
>