Ok I tried to find out at which point the service is started and when
I can access its database variable. The logs I used showed that the
services onCreate() is called after the onResume() method by my
activity. That is a bit late because I need access to the database
before onResume() to fill the
Sure. The service connection callback you seem to already have in your code.
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
06.08.2010 12:10 пользователь Bender abende...@googlemail.com написал:
Ok I tried to find out at which point the service is started and when
I can access its database
I tried the following in my activity:
mServiceConnection = new
DbServiceConnection(mDatabaseBinder);
final Intent databaseServiceIntent = new Intent(this,
DatabaseService.class);
this.bindService(databaseServiceIntent, mServiceConnection,
Context.BIND_AUTO_CREATE);
No, calling Thread.sleep() won't work.
Android framework is largely single-threaded, event-driven.
This means that your application and the framework run on the same
thread, passing control to each other, doing work in small pieces. This
thread is called the UI thread, and blocking it by
Thanks for your reply, and sorry for my late answer. :-)
I tried to get it running as a service but I don't really get how I
have to use services, binders and service connections. I'm reading a
book with an example for services but can't adopt it to my problem.
What I tried is the following:
I
Starting / binding to a service is asynchronous. You can't call bindService
and expect it to be already started and bound by the next line.
Call bindService and return control to Android by returning from onCreate or
whatever. Your service connection callback will be invoked a little later,
once
I want to get rid of the error which is telling me that there is a
leak in my app because my db gets opened twice. The db doesn't need to
be open the whole time but it is accessed quite often so I don't think
it would be very performant to open and close it for every access.
On 16 Jul., 09:10,
Bender,
put your db in a local Service. Open the db in onCreate() close it in
onDestroy(). Your Activities can bind and unbind to the Service as
many times as you like. The system will keep the service running as
long as you have an activity in the foreground process bound to it or
otherwise
mmm I'm not really sure what you are trying to achieve. Exactly, at what
times do you want to open/close the db? The db should stay open while your
application is running? So, even when you switch among activities (yours
activities)?
On Thu, Jul 15, 2010 at 6:36 PM, Bender
Thanks for your reply. I tried to open the db only in onResume() but
that doesn't work since there are db accesses in the onCreate() method
which is called before onResume() as far as I know. I think opening
and closing the db after every access would slow the app down a lot
because i'm using the
Then you could open the db in onCreate(), while in onResume() you open it
only if it's not already opened (by using SQLiteDatabase.isOpen()).
Just some ideas...;)
Hope it works!
Yuvi
On Thu, Jul 15, 2010 at 4:49 PM, Bender abende...@googlemail.com wrote:
Thanks for your reply. I tried to open
onResume / onPause are called when another activity pops in front, but
your activity stays on the screen. So this is probably a bit much.
You could try onStart / onStop, and move the code that populates views
with database data from onCreate to onStart.
-- Kostya
15.07.2010 18:49, Bender
@YuviDroid
I'm trying the following at the moment: the open() only gets called in
both onCreate() methods with:
mDb = new DbAdapter(this);
if(mDb.getDatabase() == null || !mDb.getDatabase().isOpen()) {
mDb.open();
}
The problem I'm having with this is, that
13 matches
Mail list logo