Access a database from a DialogFragment and toast a message
I have a DialogFragment which displays a simple yes/no question. When the
user presses "yes", I perform a database request (which basicaly deletes
an entry). I then toast a message to report a success or failure to the
user.
I try to avoid calling the database from the UI thread, so I created a
thread which will delete the entry, and from that thread I call a handler
in the DialogFragment to display the toast message.
My problem is that when the user presses the button, the thread is started
and the dialog is closed. As the thread is started, the data is deleted
from the database. But when I toast my message from the handler, the
DialogFragment is already detached from the parent Activity so I don't
have a context anymore to call Toast.makeText().
My question is how can I toast the message ?
I know I could create a Service to handle the database operation, but
wouldn't it be too much hassle ? Is there a simpler way ?
Thanks !
No comments:
Post a Comment