1

as per this answer it is possible to reuse android java code inside web app or desktop app frame.

so how its done step by step?

I wonder if there is a special tool to do so.

2
  • 1
    java is usually the back end of web development. u can reuse some of the java code from android.... but android has listview, recyclerview, etc. that cant be reused. Commented Oct 16, 2019 at 14:07
  • Simo and Gtomika are right, you should start with a "fresh" implementation and let the Android-Views inspire your new GUI and reuse the "backend-code" to fasten your implementation. You might even be able to reuse your POJOs. Commented Oct 16, 2019 at 14:47

2 Answers 2

2

I don't think there is a complete tutorial, as it's tedious work. The example you linked shows

Android -> Swing conversion. So I will illustrate this with some examples:

  • If you have a View in your android app, you replace it with JPanel for swing.
  • If you have a Button, you replace it with JButton
  • Sometimes elements may look similar, but they do different things, like CardView and CardPane. This complicates things.
  • There might be android Views that has no matching pair in swing, so you will have to improvise there

But it's not this simple of course. Setting the properties of the views is going to be completely different. Moreover, Android uses XML, while in Swing you have to set everything programmatically.

The only thing common is basically they are both built on Java. So my best advice is that you shouldn't try to "convert" your code. Maybe you can reuse some pure Java parts, but other than that, I suggest you re write the application using the other platforms tools.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this is enough to know that the conversion process is way painful than rewriting code in a cross platform PL.
1

you can't use android code in web app or desktop,

first you have to separate the business code from the ui code

the business code can be in a pure java module (completely reusable)

when i speak about business code i mean network calls (using retrofit for example) and any code that is pure java ..

the ui and android specific code (like Views ...) should be rewritten entirely because will not have access to android packages containing views (recycler, layouts...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.