Special kind of application...

Put your problem here if it does not fit any of the other categories.

Special kind of application...

Postby kajensmann » Wed Apr 15, 2009 12:58 pm

Hi,

i need to write an application for android, which makes use of a special initial activity. This initial activity contains the whole structure or better the logic behind the application. For example the activity initializes some variables, may start other activities (or call functions) and dependend on the result which is returned to the initial activity, other functions or activities are called. So it controls the flow of the program.
My problem is, how to keep the initial activity alive, when a subactivity is called. How can i prevent Android from killing the initial activity, if a subactivity needs some time to return? If the initial activity is killed, the current state of the program is lost. Is there any solution for this problem?
kajensmann
Freshman
Freshman
 
Posts: 4
Joined: Wed Apr 15, 2009 12:24 pm

Top

Postby WarrenFaith » Wed Apr 15, 2009 1:23 pm

Hm... Why use an activity to keep important information? I would use a singleton class to ensure that every part of the application can access the things it needs.
So if one activity is killed by android, the singleton should stay available as long as the application runs...
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby kajensmann » Wed Apr 15, 2009 2:08 pm

Thanks for the quick answer. So you mean that the singleton class should be used to store all initialized variables and the current state of the program? Ok, and the initial activity is still responsible for the program flow, like calling other activities or functions. Did you mean that?
kajensmann
Freshman
Freshman
 
Posts: 4
Joined: Wed Apr 15, 2009 12:24 pm

Postby WarrenFaith » Wed Apr 15, 2009 2:19 pm

I would split the view and logic into separate classes. The activity should only contain everything what is needed to display your UI. Every logic, status and program flow should be in separate classes. Its easier to reuse the code...
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby padde » Wed Apr 15, 2009 2:23 pm

There are several ways of doing this.. singleton is a nice and easy way as
WarrenFaith already suggested. Simply save the instance of the launch activity
and call other activity with startActivityForResult should work too.
A service running in the background is also a possible solution.
Which one to pick depends on exactly what you need and what you want to
do :)

Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby kajensmann » Wed Apr 15, 2009 3:18 pm

But how can i split UI and program logic into different classes? The first step, when openenig the application, is to determine which action must be done, like calling a function or activity. So the program starts with the 'logic' part, which should be the main program. But as far as i know, i can't initialize a program on Android starting with a normal class file :?:
kajensmann
Freshman
Freshman
 
Posts: 4
Joined: Wed Apr 15, 2009 12:24 pm

Top

Postby WarrenFaith » Wed Apr 15, 2009 9:49 pm

Thats true, you can't do that. You have to call at least one method. In case you use a singleton, you could use the constructor to setup everything you need.

I would use the Activity as the viewing part of the MVC with minimal parts of controlling. Just call some methods you need, maybe use some if-else to behave different, but separate your main logic from your activity.
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 17 guests