Ive got two开发者_StackOverflow中文版 activities in the same application. the first one is with gui(main activity) the second one is a listener which works infinite without gui.
Wierd problem occurs:
i am running the second activity with a diffrent thread so i could keep on manipulate the gui..
but for some reason, the gui losing it's focus for some reason, only when i press 'home' and come back to it, then i can continune maniuplate the gui.
it feels like after i launch the second activity, the gui activity(the main) is losing the focus. how come?
in my mainactivity i have:
setContentView(R.layout.main);
and its setted as the launcher in the manifest.
thanks,
ray.
I wouldn't implement your background activity as an Activity. Once you launch an activity it'll always be focused and brought to the foreground. It sounds like what you want to do is launch a runnable (thread) from your main activity and have this thread instantiate a normal class (non-Activity) and do whatever work it needs to do.
You may also consider implementing it as a Service
I don't think trying to have more then one Activity open at a time is right according to the "Android Model".
According to the guide:
"An activity presents a visual user interface for one focused endeavor the user can undertake"
If it had any GUI elements associated with it you might want to create a dialog. But if it is truly a background operation do what the guy before me said.
What you want to implement instead of your second activity is a Service which will be started either from your main activity or when Android is started.
精彩评论