简体   繁体   中英

Android: Minimizing and resuming a Activity

I am pretty new to Android development .

My problem is a bit tricky one.

I want to develop an application using 2 activities.

1st activity has a button . On clicking the button I want activity 2 to get started as follows:

Activity 2 will come to foreground for 2 seconds and then goes to background for 8 seconds , after which it will again come to foreground for 2 seconds and then again goes to background and the process continues.

Meanwhile both activities should continue their respective tasks.

For ex. We can have a Activity such as Music player which is playing music and another activity named Activity 2 which is downloading some files.

I have tried many things ranging from using Intents to minimizing a activity and displaying notification on notification bar. The problem with notification bar is that it on resuming the activity using notification bar it is always calling OnCreate() method thus again starting the activity.

I am able to start a activity on button click but don't know how to minimize it and then pop it up in same state .

I am using services in background for timing delays .

Please Help and share your solutions to this problem.

I have solved the problem.

The solution is to modify manifest file as :

add to main activity code

android:launchMode="singleTask"

android:clearTaskOnLaunch="true"

add to child activity code

android:launchMode="singleInstance"

android:clearTaskOnLaunch="true"

Its works perfectly for my app :)

thank you all for your kind contribution

Maybe u found solution for this issue as u said, but in any case, I would recommend reading some things.. It will help you to better understand that:

Oki.. I made some effort and organize links for you. I know it seems a lot of material, but you don't have to run to read them in next 15min.. Take it easy, read, try, learn. Take this as advice , cause once u get used to do things in a wrong way it will be much more difficult to correct them later..

Hope you find it useful.. ;) Cheers

moveTaskToBack(true); moves the whole task to back ie it moves both activities to back . Then the problem will be to move the activity to foreground which I don't know.

Have you tried using

this.moveTaskToBack(true);

I'm not sure if this is what your looking for or not. Heres the Documentation as well!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM