user1573559
user1573559

Reputation: 13

Issue with launchMode Activity

I am implementing a custom launcher. I have two activity : Activity A with launchMode : singleInstance or singleTask, and Activity B.

Activity A is main screen. There are 2 case :

So, how to resolve this? I want : Call Activity B from Activity A, then it go to Activity B directly, and when I press Home key, it go back to main screen (Activity A).

Upvotes: 1

Views: 770

Answers (2)

Harshal Benake
Harshal Benake

Reputation: 2401

try this one... remove launchmode attribute from manifest and then,call Activity B from Activity A using finish() method as follows:

finish();
            Intent intent=new Intent(getApplicationContext(),ActivityB.class);
            startActivity(intent);

Upvotes: 0

Jitesh Upadhyay
Jitesh Upadhyay

Reputation: 5260

in Activity B you can use following code with back button

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent a = new Intent(this,A.class);
        a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(a);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}     

if you wants to work with home key than override Home key with following code

 @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
       if(keyCode == KeyEvent.KEYCODE_HOME)
        {
          //yours code action
return true;
        }
       if(keyCode==KeyEvent.KEYCODE_BACK)
       {
           //yours code action
return true;
       }
      return super.onKeyDown(keyCode, event);
    }

please you may try with this as well

@Override
    public boolean dispatchKeyEvent(KeyEvent event) {

        if ( (event.getKeyCode() == KeyEvent.KEYCODE_HOME) && isLock) {
            //yours code
            return true;
        }
        else
            return super.dispatchKeyEvent(event);
    }

Upvotes: 1

Related Questions