Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of using moveTaskToBack() method in android?

I am using moveTaskToBack() method in my activity.

When I am pressing back button the activity still is visible. The back key does not work. What did I do wrong here? I want to navigate back to the previous activity.

public void onBackPressed() {     // TODO Auto-generated method stub     moveTaskToBack(true);     new Finalizer().killApp(false);     super.onBackPressed(); } 
like image 758
Dinesh Avatar asked Nov 02 '12 14:11

Dinesh


1 Answers

The purpose of moveTaskToBack:

http://developer.android.com/reference/android/app/Activity.html

moveTaskToBack(boolean nonRoot)

Move the task containing this activity to the back of the activity stack.

What you could do is:

public void onBackPressed() {     moveTaskToBack(true); // I don't think you're looking for this.     new Finalizer().killApp(false); // Neither this.     super.onBackPressed(); } 

Maybe this: Android: Go back to previous activity Something similar in your onBackPressed() after super.OnBackPressed(); Also make sure when you're hitting your back button, you're actually going in this method.

like image 60
Noman Arain Avatar answered Oct 15 '22 04:10

Noman Arain