Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development

Reply
Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

java.lang.RuntimeException: Unable to pause activity -Unable to add window android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

[ Edited ]

I am porting my android application to BB10 Android Run Time

In some places while navigating to new activity from present activity which is in activity group,I am getting errror,

07-17 06:50:58.924: E/AndroidRuntime(25321694): java.lang.RuntimeException: Unable to pause activity {com.myactivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

It is happening in some places,Not in all places,Places in which i get the error did not call onPause() method of baseactivitygroup,places in which it works on Pause method is called

MyBase Activity code is similar to below http://ericharlow.blogspot.in/2010/09/experience-multiple-android-activities.html

 

 

public class BActivityGroup extends ActivityGroup {

private ConfirmActionListener _confListener; 
private DeleteActionListener _delListener; 
private TPINConfListener _tpinListener;
private ArrayList<String> mIdList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    System.out.println("On Create Of BaseActivity Group>>>>>>>>>>");
    if (mIdList == null) mIdList = new ArrayList<String>();
}

public void startChildActivity(String id, Intent intent) {
    System.out.println("Within startChildActivity>>>>>>> BActivityGroup");
    Window window = getLocalActivityManager().startActivity(id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    if (window!=null) {
        mIdList.add(id);
        setContentView(window.getDecorView());
    }
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    System.out.println("On Pause Of BaseActivity Group>>>>>>>>>>");
    super.onPause();
}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    System.out.println("onDestroy Of BaseActivity Group>>>>>>>>>>");
    super.onDestroy();
}


@Override
public void finishFromChild(Activity child) {
    System.out.println("Within finishFromChild>>>>>>> BaseActivityGroup");
    LocalActivityManager manager = getLocalActivityManager();
    int index = mIdList.size()-1;

    if (index < 1) {
        finish();
    return;
    }
    manager.destroyActivity(mIdList.get(index), true);
    mIdList.remove(index);
    index--;
    String lastId = mIdList.get(index);
    Intent lastIntent = manager.getActivity(lastId).getIntent();
    Window newWindow = manager.startActivity(lastId, lastIntent);
    setContentView(newWindow.getDecorView());
}   
public void replaceContentView(String id, Intent newIntent) {
    View view = getLocalActivityManager().startActivity(id,
            newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
            .getDecorView();
    this.setContentView(view);
}

public void setConfirmActionListener(ConfirmActionListener listener) {
    _confListener=listener;
}

public void onConfirm() {
    if (_confListener!=null) {
        _confListener.onConfirm();
    }
}

public void setDeleteActionListener(DeleteActionListener listener) {
    _delListener=listener;
}

public void onDelete(String tag) {
    if (_delListener!=null) {
        _delListener.onDelete(tag);
    }
}

public void setTPINConfListener(TPINConfListener listener) {
    _tpinListener=listener;
}

public void onTPINConfirm(String tPIN) {
    if (_tpinListener!=null) {
        _tpinListener.onTPINEntered(tPIN);
    }
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
    //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
    return true;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    System.out.println("On onKeyUp Of BaseActivity Group>>>>>>>>>>");
    if (keyCode == KeyEvent.KEYCODE_BACK) {
    onBackPressed();
    return true;
    }
    return super.onKeyUp(keyCode, event);
}

public void onBackPressed () {
    System.out.println("On onBackPressed Of BaseActivity Group>>>>>>>>>>");
    int length = mIdList.size();
    if ( length > 1) {
    Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
    current.finish();
    }
    else
    {
        finish();
    }
}

 

This issue happens in Blackberry Q5 device,no issues in BB Z10 device ,

 

 

Any Ideas how to resolve this issue.

 

Thanks

Rakesh

Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Re: java.lang.RuntimeException: Unable to pause activity -Unable to add window android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

Hi,

 

I am attaching screenshot of logs where crashing scenario happens

 

IssueActivityGroup.jpg

Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Re: java.lang.RuntimeException: Unable to pause activity -Unable to add window android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

This issue happens in 10.1 device versions(Q5/Crashing issue) ,there is no crashing issue in 10.0 OS device versions(z10)

Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: java.lang.RuntimeException: Unable to pause activity -Unable to add window android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

Well, is your activity running? Smiley Happy

 

I'd suggest adding some more logging to track each of your Actvitiy's lifecycle.

Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Re: java.lang.RuntimeException: Unable to pause activity -Unable to add window android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

[ Edited ]

Hi,

 

One more issue,i found that is if i kept the second child activity idle for 5 seconds,I am getting this same issue that was stated earlier ,On Pause() of Activity nor Activity group is not getting called

 

Any ideas why this issue.and how to handle this case?It is not happening in all cases,but in some places.second child activity is common confirmation page Activity which is common used across all the services,which i use,But the issue is happening on some particular set of services.

 

 

Thanks

Rakesh

New Member
Posts: 1
Registered: ‎12-13-2013
My Device: Blackberry Z10
My Carrier: Claro

Re: java.lang.RuntimeException: Unable to pause activity -Unable to add window android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

Hi.

I have same problem... someone found a solution for this. I would greatly appreciate know