这里是我的代码
View view = getLocalActivityManager().startActivity("saved",
new Intent(v.getContext(),Saved_jobs.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
replaceView(view);
我正在使用此代码在tabHost中打开新活动并完美地打开活动并且所有控制点击事件都正常工作
但是当我点击imageview然后应用程序崩溃
Imageview点击事件代码
imageView.setBackgroundResource(R.drawable.starapplied);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder = new AlertDialog.Builder(RecentlyViewd.this);
builder.setTitle("Are you sure you want to delete this job?");
// builder.setMessage("whould You like to save job");
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
db.DeleteLocation(v.getTag().toString());
Toast.makeText(getApplicationContext(), "Job Deleted !",10).show();
startActivity(new Intent(RecentlyViewd.this,RecentlyViewd.class));
finish();
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
});
builder.show();
}
});
logcat的:
01-03 15:54:11.205: E/ActivityThread(1092): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
01-03 15:54:11.205: E/BinaryDictionaryGetter(1092): Could not find a dictionary pack
01-03 15:54:17.685: E/AndroidRuntime(2771): FATAL EXCEPTION: main
01-03 15:54:17.685: E/AndroidRuntime(2771): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@b67b6b98 is not valid; is your activity running?
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.ViewRootImpl.setView(ViewRootImpl.java:585)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.Window$LocalWindowManager.addView(Window.java:547)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.app.Dialog.show(Dialog.java:277)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
01-03 15:54:17.685: E/AndroidRuntime(2771): at com.jobDiagnosis.RecentlyViewd$SavedAdapter$1.onClick(RecentlyViewd.java:196)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.View.performClick(View.java:4084)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.view.View$PerformClick.run(View.java:16966)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.os.Handler.handleCallback(Handler.java:615)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.os.Handler.dispatchMessage(Handler.java:92)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.os.Looper.loop(Looper.java:137)
01-03 15:54:17.685: E/AndroidRuntime(2771): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-03 15:54:17.685: E/AndroidRuntime(2771): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 15:54:17.685: E/AndroidRuntime(2771): at java.lang.reflect.Method.invoke(Method.java:511)
01-03 15:54:17.685: E/AndroidRuntime(2771): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-03 15:54:17.685: E/AndroidRuntime(2771): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-03 15:54:17.685: E/AndroidRuntime(2771): at dalvik.system.NativeStart.main(Native Method)
01-03 15:54:19.475: E/Trace(2806): error opening trace file: No such file or directory (2)
01-03 15:54:19.815: E/ActivityThread(1092): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
01-03 15:54:19.815: E/BinaryDictionaryGetter(1092): Could not find a dictionary pack
01-03 15:54:19.925: E/ActivityThread(1092): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
01-03 15:54:19.925: E/BinaryDictionaryGetter(1092): Could not find a dictionary pack
01-03 15:54:20.265: E/BufferQueue(786): [] drainQueueLocked: BufferQueue has been abandoned!
请帮帮我
对我来说这是非常重要的任务
感谢Adavance
答案 0 :(得分:1)
如果您使用的是 TabGroupActivity ,请更改为:
这
AlertDialog.Builder builder = new AlertDialog.Builder(RecentlyViewd.this);
到
AlertDialog.Builder builder = new AlertDialog.Builder(getParent());
答案 1 :(得分:0)
而不是
AlertDialog.Builder builder = new AlertDialog.Builder(RecentlyViewd.this);
使用它。
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());