Coder Social home page Coder Social logo

Comments (12)

danieldisu avatar danieldisu commented on July 23, 2024

The Intent obtained in the getIntent is the original one, it ignores all the changes made during the ActivityStarter.fill().

One way to fix this would be to save the state in the Bundle "outState" that is provided in the onSaveInstanceState. And use the bundle provided in the onCreate method to restore the state if present.

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

You are right. I made this change to allow saving state on property delegates (Kotlin). What do you think about the following generation proposition?

Original:

public class MainActivity extends Activity {
  @Arg(optional = true) String name;
}

Generated:

public final class MainActivityStarter {
  private static final String NAME_KEY = "com.example.activitystarter.nameStarterKey";

  public static void fill(MainActivity activity) {
    Intent intent = activity.getIntent();
    if(intent.hasExtra(NAME_KEY))
         activity.name = intent.getStringExtra(NAME_KEY);
  }
  
  public static void save(MainActivity activity, Bundle bundle) {
      bundle.putString("com.example.activitystarter.nameStarterKey", activity.name);
  }

  //...
}

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

@danieldisu Can you check version issue_24-SNAPSHOT

compile 'com.github.MarcinMoskala:ActivityStarter:issue_24-SNAPSHOT'

from activitystarter.

danieldisu avatar danieldisu commented on July 23, 2024

Thank you for you fast response!!

I've tried it and is still not working, it's almost there!

The Save method now is 100% OK, but it's also needed to change the FILL method, to also receive the bundle, in order to load the saved info from it when present.
The thing is that you have to check if the bundle is null, if it's null load it from the intent, if not, load it from the bundle!

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

I think it should be ok in current SNAPSHOT

from activitystarter.

danieldisu avatar danieldisu commented on July 23, 2024

The generic method ActivityStarter.fill() still doesn't have the possibility to pass the bundle.

But using the ActivityNameStarter.fill(activity, bundle) method works like a charm!

Do you think it would be possible to add an overloaded method ActivityStarter.fill() that receives the Bundle?

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

In the published version, there is ActivityStarter.fill(this, savedInstanceState); Sorry for the delay, but in the moment I am really overloaded with projects. Although I tested it and here you can see example usage.

from activitystarter.

danieldisu avatar danieldisu commented on July 23, 2024

Everything is working now!

Thanks!!

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

But this is not the solution because it does not allow Kotlin property delegates to read state from saved bundle. I am still working on this issue.

from activitystarter.

danieldisu avatar danieldisu commented on July 23, 2024

I see the problem, but it's going to be a hard one to crack because there is no way to access the savedInstanceState Bundle outside the lifecycle methods.

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

I see now that there is no way to do it. I will fill values if savedInstanceState is not null and if the property is read-write.

from activitystarter.

MarcinMoskala avatar MarcinMoskala commented on July 23, 2024

Today I finally had more time to fix this problem. From new version, Kotlin needs also fill called for loading saved state (if we need it). I just distributed it in beta version 1.10

from activitystarter.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.