我想删除一个活动的一个按钮,但是当我启动它时:
Intent inte = new Intent(PasswordConfirmationActivity.this,
IndexActivity.class);
UserAuthentication UA = new UserAuthentication();
control = UA.UserControl(EdtText.getText().toString());
inte.putExtra("confirmation", control);
startActivity(inte);
finish();
它给了我错误 当另一个活动正在运行时,该活动也在运行。
这就是我删除按钮的代码:
Boolean loginControl = getIntent().getBooleanExtra("confirmation",false);
if (loginControl == true) {
ViewGroup layout = (ViewGroup) ButtonClick2.getParent();
if(null!=layout)
layout.removeView(ButtonClick2);
}
这是loccat:
08-13 15:37:13.676: E/WindowManager(17128): Activity tr.com.turkcell.shmobile.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@421bfcb0 that was originally added here
08-13 15:37:13.676: E/WindowManager(17128): android.view.WindowLeaked: Activity tr.com.turkcell.shmobile.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@421bfcb0 that was originally added here
08-13 15:37:13.676: E/WindowManager(17128): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
08-13 15:37:13.676: E/WindowManager(17128): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
08-13 15:37:13.676: E/WindowManager(17128): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
08-13 15:37:13.676: E/WindowManager(17128): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
08-13 15:37:13.676: E/WindowManager(17128): at android.view.Window$LocalWindowManager.addView(Window.java:549)
08-13 15:37:13.676: E/WindowManager(17128): at android.app.Dialog.show(Dialog.java:277)
08-13 15:37:13.676: E/WindowManager(17128): at android.app.ProgressDialog.show(ProgressDialog.java:116)
08-13 15:37:13.676: E/WindowManager(17128): at android.app.ProgressDialog.show(ProgressDialog.java:99)
08-13 15:37:13.676: E/WindowManager(17128): at android.app.ProgressDialog.show(ProgressDialog.java:94)
08-13 15:37:13.676: E/WindowManager(17128): at tr.com.turkcell.shmobile.MainActivity$GetProduts.onPreExecute(MainActivity.java:188)
08-13 15:37:13.676: E/WindowManager(17128): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
08-13 15:37:13.676: E/WindowManager(17128): at android.os.AsyncTask.execute(AsyncTask.java:534)
08-13 15:37:13.676: E/WindowManager(17128): at tr.com.turkcell.shmobile.MainActivity$1$1.run(MainActivity.java:59)
08-13 15:37:13.676: E/WindowManager(17128): at android.app.Activity.runOnUiThread(Activity.java:4591)
08-13 15:37:13.676: E/WindowManager(17128): at tr.com.turkcell.shmobile.MainActivity$1.onClick(MainActivity.java:56)
08-13 15:37:13.676: E/WindowManager(17128): at android.view.View.performClick(View.java:4084)
08-13 15:37:13.676: E/WindowManager(17128): at android.view.View$PerformClick.run(View.java:16966)
08-13 15:37:13.676: E/WindowManager(17128): at android.os.Handler.handleCallback(Handler.java:615)
08-13 15:37:13.676: E/WindowManager(17128): at android.os.Handler.dispatchMessage(Handler.java:92)
08-13 15:37:13.676: E/WindowManager(17128): at android.os.Looper.loop(Looper.java:137)
08-13 15:37:13.676: E/WindowManager(17128): at android.app.ActivityThread.main(ActivityThread.java:4754)
08-13 15:37:13.676: E/WindowManager(17128): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:37:13.676: E/WindowManager(17128): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 15:37:13.676: E/WindowManager(17128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-13 15:37:13.676: E/WindowManager(17128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-13 15:37:13.676: E/WindowManager(17128): at dalvik.system.NativeStart.main(Native Method)
08-13 15:37:15.266: D/ActivityThread(17128): handleResumeActivity now pri:0
08-13 15:37:15.266: D/ActivityThread(17128): handleResumeActivity set pri:0
08-13 15:37:17.086: D/AndroidRuntime(17128): Shutting down VM
08-13 15:37:17.086: W/dalvikvm(17128): threadid=1: thread exiting with uncaught exception (group=0x41b6a318)
08-13 15:37:17.086: E/AndroidRuntime(17128): FATAL EXCEPTION: main
08-13 15:37:17.086: E/AndroidRuntime(17128): java.lang.RuntimeException: Unable to start activity ComponentInfo{tr.com.turkcell.shmobile/tr.com.turkcell.shmobile.IndexActivity}: java.lang.NullPointerException
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.os.Looper.loop(Looper.java:137)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.ActivityThread.main(ActivityThread.java:4754)
08-13 15:37:17.086: E/AndroidRuntime(17128): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:37:17.086: E/AndroidRuntime(17128): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 15:37:17.086: E/AndroidRuntime(17128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-13 15:37:17.086: E/AndroidRuntime(17128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-13 15:37:17.086: E/AndroidRuntime(17128): at dalvik.system.NativeStart.main(Native Method)
08-13 15:37:17.086: E/AndroidRuntime(17128): Caused by: java.lang.NullPointerException
08-13 15:37:17.086: E/AndroidRuntime(17128): at tr.com.turkcell.shmobile.IndexActivity.onCreate(IndexActivity.java:75)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.Activity.performCreate(Activity.java:5008)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
08-13 15:37:17.086: E/AndroidRuntime(17128): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
答案 0 :(得分:0)
使用view.setVisibility(View.Gone);它将从屏幕上删除按钮。
e.g:
Boolean loginControl = getIntent().getBooleanExtra("confirmation",false);
if (loginControl) {
ViewGroup layout = (ViewGroup) ButtonClick2.getParent();
toBeRemovedButton.setVisibility(View.Gone);
}
要重新启动当前活动,您可以像往常一样使用intent完成并重新创建它。但请记住,重新创建后,将再次调用oncreate()并刷新布局,包括您可能已删除的视图。
答案 1 :(得分:0)
完成()一个活动后,你可以用一个额外的Bundle来绘制它以隐藏Button ..