Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old November 6th, 2012, 07:55 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2012
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Need suggestion for porting from C to Java app

I've programmed in c/c++ in the last 15 years but I've little
experience in Java (and Android), so I would like a suggestion
on how to structure a very simple (but computationally intensive)
app which has the following general characteristics (no details needed).

The app has some data (say 2MB) statically stored.
When the app starts this data is preprocessed and
a large structure of about 40Mb is created.

After the initialization, the app has one text field
for input, one for output and a button (for start/stop).

The user enters a query then press the start button.
The app computes a result using the large array.
If the calculation on the input takes too long,
the user can stop the processing with the stop button and
start again with a new input.

When I was doing this under windows/linux with C/C++, I had
no problems: I used a large global array and two threads,
one to draw interface and respond to user
(mouse, clicks, etc.) and one to perform the computation.

Which is the standard (best) way to structure this kind of app
in Java/Android ?

Should I use an Activity for the graphic interface and a
Service for the computation ? Can I build the large array in the
Activity when the app starts and pass a reference to it to the Service every time Start button is pushed ?

I just need to be pointed in the right direction, to avoid
some blind alleys.

In a sense using c/c++ would be better, but I read that
developing in Java (for Android) is much easier so I will
try first with Java and revert to C only if the app will turn out
to be too slow.

thanks,
Giovanni

diddum is offline  
Reply With Quote
sponsored links
Old November 7th, 2012, 09:06 AM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

I would suggest creating a sort of splash screen where you load all of your data and populate your data structure. Once this task completes, I would spawn a new activity that contains your UI controls. Java and subsequently Android are event driven in nature. Once you have your UI set up, you will need to register a listener with your button object that will be fired automatically when it is clicked. Inside this listener, you will need to spawn off a new thread that will perform the network related code. When the code completes, you will need to use a Handler object to notify the UI thread that it has completed and to display the result. Rather than using a Thread and Handler object, you can simplify things by using Android's built-in AsyncTask which handles all of the threading issues for you.
__________________
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
Old November 7th, 2012, 12:25 PM   #3 (permalink)
New Member
 
Join Date: Aug 2010
Posts: 12
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

With 15 years of C/C++ experience and a computationally expensive program you might be better off checking out the NDK. Especially if your existing codebase is significant. It should allow you to use much of your existing code. You could still do the UI in java and just have your processing thread go through your C-code. It really is dependent on the size of the code your converting though as NDK has its own idiosyncracies, but the support for NDK has improved quite a bit in the last couple years when there was virtually no support or examples.
galth is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:53 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.