0

我正在将我的 android 应用程序移植到 BB10 Android Run Time

在某些地方,从活动组中的当前活动导航到新活动时,我遇到了错误,

07-17 06:50:58.924: E/AndroidRuntime(25321694): java.lang.RuntimeException: 无法暂停活动 {com.myactivity}: android.view.WindowManager$BadTokenException: 无法添加窗口 -- 令牌 null 不是有效的; 您的活动正在运行吗?

它发生在某些地方,不是在所有地方,我得到错误的地方没有调用 baseactivitygroup 的 onPause() 方法,它在 Pause 方法上工作的地方被调用

MyBase Activity 代码类似于下面 http://ericharlow.blogspot.in/2010/09/experience-multiple-android-activities.html

package com.rak.ui;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;

import com.xxx.interfaces.ConfirmActionListener;

import com.xxx.interfaces.DeleteActionListener;
import com.xxx.interfaces.TPINConfListener;

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();
    }
}

}

黑莓 Q5 设备出现此问题,BB Z10 设备没有问题,

4

0 回答 0