禁用主页按钮,给我一个错误

时间:2015-01-25 15:58:33

标签: android listview android-homebutton

我知道这已被问了几次,但我实际上使用所提供的解决方案时遇到了一些问题。 我想禁止访问特定活动的主页按钮。

非常感谢任何帮助。 我认为我的问题是OnCreate方法下的第一个声明,但是idk。

这是我的代码:

public void onCreate(Bundle savedInstanceState) {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main_activity2);
    background2= (RelativeLayout) findViewById(R.id.background);
    final ListView theListView = (ListView) findViewById(R.id.listView);
    Intent calledActivity=getIntent();
    final List pe=calledActivity.getExtras().getStringArrayList("Caller1");

    String []s =new String[pe.size()];
    for(int i=0;i<pe.size();i++)
    {
        s[i]=(String)pe.get(i);
    }

    final ListAdapter theAdapter= new ArrayAdapter<String>(this,   android.R.layout.simple_list_item_1, pe);
    theListView.setAdapter(theAdapter);
    final int cnt=1;

    theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String s1 = String.valueOf(parent.getItemAtPosition(position));
            pe.remove(s1);
            if(pe.size()==0)
            {
                Intent goback;
                goback = new Intent(MainActivity2.this, MainActivity.class);
                startActivity(goback);``
            }
            ((BaseAdapter)theAdapter).notifyDataSetChanged();



        }
    });



    }

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    return false;
}
@Override
public void onAttachedToWindow()
{
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    super.onAttachedToWindow();
}

logcat的:

01-25 11:00:42.486    1090-1090/com.example.epiclapser.noprocrastinate D/libEGL﹕ loaded /system/lib/egl/libEGL_emulation.so
01-25 11:00:42.506    1090-1090/com.example.epiclapser.noprocrastinate D/﹕ HostConnection::get() New Host Connection established 0x2a1e8ed0, tid 1090
01-25 11:00:42.526    1090-1090/com.example.epiclapser.noprocrastinate D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_emulation.so
01-25 11:00:42.536    1090-1090/com.example.epiclapser.noprocrastinate D/libEGL﹕ loaded /system/lib/egl/libGLESv2_emulation.so
01-25 11:00:42.686    1090-1090/com.example.epiclapser.noprocrastinate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-25 11:00:42.706    1090-1090/com.example.epiclapser.noprocrastinate D/OpenGLRenderer﹕ Enabling debug mode 0
01-25 11:07:14.726    1090-1090/com.example.epiclapser.noprocrastinate D/dalvikvm﹕ GC_FOR_ALLOC freed 268K, 14% free 2751K/3180K, paused 133ms, total 163ms
01-25 11:07:15.286    1090-1090/com.example.epiclapser.noprocrastinate D/dalvikvm﹕ GC_FOR_ALLOC freed 90K, 15% free 2814K/3280K, paused 222ms, total 267ms
01-25 11:07:15.366    1090-1090/com.example.epiclapser.noprocrastinate I/dalvikvm-heap﹕ Grow heap (frag case) to 3.509MB for 635812-byte allocation
01-25 11:07:15.626    1090-1099/com.example.epiclapser.noprocrastinate D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 13% free 3433K/3904K, paused 263ms, total 263ms
01-25 11:07:16.048    1090-1090/com.example.epiclapser.noprocrastinate D/dalvikvm﹕ GC_FOR_ALLOC freed 2K, 13% free 3430K/3904K, paused 284ms, total 300ms
01-25 11:07:16.096    1090-1090/com.example.epiclapser.noprocrastinate I/dalvikvm-heap﹕ Grow heap (frag case) to 3.982MB for 500416-byte allocation
01-25 11:07:16.216    1090-1099/com.example.epiclapser.noprocrastinate D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 11% free 3919K/4396K, paused 116ms, total 116ms
 01-25 11:07:16.636    1090-1090/com.example.epiclapser.noprocrastinate D/AndroidRuntime﹕ Shutting down VM
 01-25 11:07:16.646    1090-1090/com.example.epiclapser.noprocrastinate W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41465700)
 01-25 11:07:16.696    1090-1090/com.example.epiclapser.noprocrastinate E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
        at android.os.Parcel.readException(Parcel.java:1435)
        at android.os.Parcel.readException(Parcel.java:1385)
        at   android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:835)
        at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5034)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1399)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
        at android.view.Choreographer.doCallbacks(Choreographer.java:562)
        at android.view.Choreographer.doFrame(Choreographer.java:532)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
        at android.os.Handler.handleCallback(Handler.java:730)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案