0

I'm working on an app that allows you to track the number of rows and stitches per row in a crochet or knitting project. I'd like to implement a "New Project" button that creates a new activity for the new project complete with black counts and everything.

The only thing is, I know how to create a new activity/page manually -- I have no idea how to do this on the push of a button -- that is, not needing to create x number of activities to preload, but instead, letting the "New Project" button create the new activity -- and have it be a copy of the prior one.

I hope this question is clear enough!

RITheory
  • 43
  • 6

2 Answers2

0

Before switching to another activity you can save the current state of the current activity in any permanent storage, like Shared Preferences... along with a counter as an id for each view included in ur current activity. Then in new activity you can create all the views again with the same details from the Shared Preferences or so.. You can also use a serializable class.. but i will take a long route to save all properties related to a view.

Bhavna
  • 836
  • 2
  • 6
  • 19
0

To reate a new activity on the push of a button you can simply get your button from your layout, add an onclicklistener and start a new Activity from that. Have a look at this stack overflow question: How to start new activity on button click

In case you want the new Activity to be a copy of the previous one, it is probably best to create a new Activity and apply the same data and UI state as the previous one.

To do this, you can add all Activity data to the extras of the intent to start the Activity (Lists/vectors can be added using the parcelable interface) and then you can use this data in the on create() of your new Activity. (By checking if a certain extra is null or not, you can differentiate between the first activity of your app or all subsequent ones)

If you want me to be more specific, please post your source code so I can have a look at your data model.

Community
  • 1
  • 1
Jeroen Mols
  • 3,436
  • 17
  • 24