Rob R.
Rob R.

Reputation: 85

Is there a simple way to duplicate an Android activity in the same project

I have an Activity that, with a few modifications, would work extremely well as another part of the app I'm working on. I was wondering if it's possible to easily duplicate an Activity in Android Studio without needing to manually copy all of its dependencies (activity_my.xml for example).

Upvotes: 3

Views: 7779

Answers (1)

Micha F.
Micha F.

Reputation: 634

To get it right: You have code you want to reuse in another Activity.

Now, the way I would do this would not be to copy the reused code (because if you want to modify it, you have to modify both copies, which is tedious work).

I'd create a base-activity, that has the functionality that both of your Activities need. This functionality would have to be slightly abstracted so that both activites could use this functionality by extending this BaseActivity and use it for their individual purposes.

If you post some code (the part of code both of your activities should have), I could update my answer to show you how that would look like in your case.

Upvotes: 3

Related Questions