package com.org.myOxygen.activities;
import java.util.Stack;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class ApplicationTabActivityGroup extends ActivityGroup{
private static Stack<String> stack;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (stack == null) stack = new Stack<String>();
//start default activity
push("Search Activity", new Intent(this, ApplicaitonActivity.class));
}
@Override
public void finishFromChild(Activity child) {
pop();
}
@Override
public void onBackPressed()
{
pop();
}
public void push(String id, Intent intent)
{
Window window = getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
stack.push(id);
setContentView(window.getDecorView());
}
}
public void pop()
{
if (stack.size() == 1) finish();
LocalActivityManager manager = getLocalActivityManager();
manager.destroyActivity(stack.pop(), true);
if (stack.size() > 0)
{
Intent lastIntent = manager.getActivity(stack.peek()).getIntent();
Window newWindow = manager.startActivity(stack.peek(), lastIntent);
setContentView(newWindow.getDecorView());
}
}
}
Я получаю сообщение об ошибке
Intent lastIntent = manager.getActivity(stack.peek()).getIntent();
Ошибка: NullPointerException
.
Что там может быть не так?
изменить - 1
11-26 14:58:57.256: E/AndroidRuntime(557): FATAL EXCEPTION: main
11-26 14:58:57.256: E/AndroidRuntime(557): java.lang.NullPointerException
11-26 14:58:57.256: E/AndroidRuntime(557): at com.org.myOxygen.activities.SearchTabActivityGroup.pop(SearchTabActivityGroup.java:59)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.org.myOxygen.activities.SearchTabActivityGroup.onBackPressed(SearchTabActivityGroup.java:36)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.app.Activity.onKeyUp(Activity.java:1888)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.KeyEvent.dispatch(KeyEvent.java:1061)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.app.Activity.dispatchKeyEvent(Activity.java:2068)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1643)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.widget.TabHost.dispatchKeyEvent(TabHost.java:275)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1667)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1102)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.app.Activity.dispatchKeyEvent(Activity.java:2063)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1643)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2471)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2441)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.view.ViewRoot.handleMessage(ViewRoot.java:1735)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.os.Looper.loop(Looper.java:123)
11-26 14:58:57.256: E/AndroidRuntime(557): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-26 14:58:57.256: E/AndroidRuntime(557): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 14:58:57.256: E/AndroidRuntime(557): at java.lang.reflect.Method.invoke(Method.java:521)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-26 14:58:57.256: E/AndroidRuntime(557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-26 14:58:57.256: E/AndroidRuntime(557): at dalvik.system.NativeStart.main(Native Method)
Вот трассировка стека!