Recommended ways to produce app portable between A

2020-03-01 06:14发布

I'm developing an application for Android, and I'm thinking that it's functionality might be useful on other (Java-running) platforms (say a regular desktop app -- although I hope that the other platform(s) involved are immaterial to the question at hand).

It's unlikely that the UI will be in any way portable (there's just too much of a difference between a good touch-capable, 4in screen UI, and a mouse-and-keyboard 19in screen UI), so I'm happy enough reimplementing that separately.

However, the core "business logic" (ugh, horrid word) and model (data storage) classes could, in theory, be reused in managing the core app. I've noticed that there aren't a lot of classes I'm writing that don't end up referencing some Android-specific bits (I've got XML resources files, images, and SQLite databases, as examples). Basically everything I've written so far has at least one Android-related import.

My question is twofold:

  • What tools are available out there to help me use Android-related classes and features (eg resources, databases) on non-Android platforms; and
  • What classes, features, etc of the Android platform should I completely avoid using (for the sake of simplicity, let's exclude UI-related items) due to non-portability, and what should I use instead to improve portability.

Answers that consist of "hahahaha, you're doomed" are OK, as long as there's some rationale provided.

(P.S. I'd make this community wiki if that was still available; this seems like a perfect CW question to me -- a list of Android portability tips and tools)

8条回答
该账号已被封号
2楼-- · 2020-03-01 06:39

I started off doing something similar - I wanted to write an app for Android, Blackberry and J2ME. Conceptually, you can layer your design such that platform-specific components (UI, network access, data storage) are separated from the core business logic.

In practice, I don't find this satisfactory. The issues I faced all related to the core version of Java being different in the different platforms (in Blackberry it is based on J2Se 1.4, while Android used Java 6 as base). This led to annoyances like

  • Not able to reuse code that uses generics
  • My preferred classes not being available uniformly (for example, forced to use Vector over List)

I have opened discussions regarding this on SO (here and here), but couldn't reach a conclusion.

查看更多
Viruses.
3楼-- · 2020-03-01 06:41

The logging layer can be made portable by using the Simple Logging Facade for Java(SLF4J) which is available for java/log4j and for android.

查看更多
登录 后发表回答