以前的android活动开放了

时间:2013-01-19 13:04:39

标签: android android-intent android-activity android-cursor

在我的应用程序中,我创建了一个通知功能,通过该功能调用Activity_1。在Activity_1中,我有一个完成的任务按钮,它调用以下代码:

public void completeTask(){
        taskDBAdapter.deleteReminder(rowId);
    taskDBAdapter.close();
    Intent intent = new Intent(this, TaskManagerActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("CloseActivity", "true");
    startActivity(intent);
    finish();
    }

Activity_1 oncreate code -

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tasks_complete_layout);
        buttonTaskDone = (Button)findViewById(R.id.CompleteTaskButton);
        registerButtonListenersAndSetDefaultText();
        taskDBAdapter = new TasksDBAdapter(this);
        taskDBAdapter.open();
        if(getIntent() != null){
            Bundle extras = getIntent().getExtras();
            rowId = extras != null ? extras.getLong(TasksDBAdapter.KEY_ROWID) : -1;
        }

        closeHandler = new Handler() {
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch(msg.what) {
                case 0:
                    finish();
                    break;
                }
            }
        };
    }

现在TaskManagerActivity是我的应用启动时加载的活动。一旦发生这种情况,如果我继续按下后退按钮并在执行代码后退出应用程序:

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if(isBackPressed){
                moveTaskToBack(true);
                mDBHelper.close();
                finish();
            }else{
                Toast.makeText(getApplicationContext(), "Please press back again to exit application", Toast.LENGTH_SHORT).show();
                isBackPressed = true;
            }

            return true;
        }
        return super.onKeyDown(keyCode, event); 
    }

但是当我从菜单中重新打开我的应用程序时,它会崩溃。

TaskManagerActivity oncreate code -

@Override
    public void onCreate(Bundle savedInstanceState) {

        Log.i(TAG, "getItnnt>" + getIntent().getStringExtra("CloseActivity"));
        if(getIntent().getStringExtra("CloseActivity") == "true"){
            Log.i(TAG, "inside closign activity");
            TaskCompleteActivity.closeHandler.sendEmptyMessage(0);
        }

        //setTheme(R.style.HoloTheme);
        settingsDBAdapter = new SettingsDBAdapter(this);
        settingsDBAdapter.open();

        listNameDBAdapter = new ListNameDBAdapter(this);
        listNameDBAdapter.open();

        setSettingsTheme();

        setContentView(R.layout.layout_task_manager);

        quickAddButton = (Button) findViewById(R.id.QuickAddButtonId);
        listsButton = (Button) findViewById(R.id.Lists);
        quickAddTaskText = (EditText) findViewById(R.id.QuickAddEditTextId);

        mDBHelper = new TasksDBAdapter(this); 
        mDBHelper.open();

        fillData();

        LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
        popupView = layoutInflater.inflate(R.layout.task_list_popup, null);
        popUpListView = (ListView)popupView.findViewById(R.id.list);

        popupCreateListView = layoutInflater.inflate(R.layout.popup_create_list, null);

        //code to create long press on any list item and calls onCreateContextMenu method
        registerForContextMenu(getListView());

        registerButtonListenersAndSetDefaultText();
        super.onCreate(savedInstanceState);

    }

我附加了LogCat:

01-19 18:32:15.835: E/AndroidRuntime(1211): FATAL EXCEPTION: main
01-19 18:32:15.835: E/AndroidRuntime(1211): java.lang.RuntimeException: Unable to resume activity {ray.kaushik.simple.task.manager/ray.kaushik.simple.task.manager.ReminderModificationActivity}: java.lang.IllegalStateException: trying to requery an already closed cursor  android.database.sqlite.SQLiteCursor@412a6b50
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.os.Looper.loop(Looper.java:137)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invokeNative(Native Method)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invoke(Method.java:511)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at dalvik.system.NativeStart.main(Native Method)
01-19 18:32:15.835: E/AndroidRuntime(1211): Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor  android.database.sqlite.SQLiteCursor@412a6b50
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.Activity.performRestart(Activity.java:5051)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.Activity.performResume(Activity.java:5074)
01-19 18:32:15.835: E/AndroidRuntime(1211):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
01-19 18:32:15.835: E/AndroidRuntime(1211):     ... 10 more

任何人都可以指导,因为我是Android开发的新手。非常感谢。

0 个答案:

没有答案