Android Hybrid application using Native Android functions

476 Views Asked by At

Currently i am developing an Android Hybrid application. I am pretty new to Android development but picking up new things pretty much every day. This Hybrid application is build upon the Sencha Touch 2.3.1 framework. The project consists out of the following of main goals.

Functionality:

  • Getting the current GPS location. (Backed by 2G/3G or WiFi if needed)
  • Reading the current accelerometer values. (Used for a fall-detection algorithm)
  • Scanning QR codes. (I will probably use a library for this function)
  • Setting a timer and let it run in the background.
  • All of the above should 'run' in the Native part of the application.

General question: What would be the best way of doing this, in terms of architecture/base structure?

To get a little more specific on the answer i would like to get, here is some more information.

Currently the native part (Activity) of the application looks somewhat like this. It declares and initializes the WebView and loads the URL which refers to the host where my Sencha Touch application is hosted. So far this is the only Activity/Class i have. And also works properly.

I am using the following bridge to communicate back and forth between the hybrid and native part of the application. In the example on GitHub they stuffed all of the functionality in one Java class. (Activity)

In my case this would mean for my project, that all of the Hybrid to Native function calls, like getting the current GPS status, set a timer in the background or start the camera will reside in the main Activity. Thus getting quite big in time, i could imagine.

Sub question: Is this the way to go, or should i split up all of the core functionality in separate classes?

Scenario:

The GPS sensor takes quite some time to get a fix, so the user should not be interrupted while the GPS keeps searching for the current coordinates. (Again this can be backed by 2G/3G or WiFi if needed and available)

Sub question: Should this or any other background functionality be handled in a separate thread? Or in the same Activity where the WebView resides? Or can i just simply create a new thread within the Activity that handles the GPS and/or other functionality that require to run on the background?


As you can see i am trying to figure out the best way of structuring the application on the Native side.

For the threading part (Functionality that runs in the background, such as a timer or GPS that waits for the correct coordinates) i wanted to use IntentService, because the functionality has to keep running and also finishing their tasks, even when the application is not active/minimized. Plus the same task is bound to be handled again. (Re-using the thread?) So when i speak of threading or threads in this question, i mean using the IntentServices.

I hope i was clear enough. Thanks for reading so far.

(Pseudo)Coding answers are appreciated, but showing me the best/correct structure (Image or 'just in words' -like) would be preferred. Then again, do as you prefer.

0

There are 0 best solutions below