设备进入睡眠状态后清除主要活动

时间:2012-05-08 06:03:23

标签: java android eclipse

实际上,我已经开发了我的Android应用程序版本10(2.33),但是我发现了这个问题,当我在移动设备上运行应用程序时,它工作正常但是有一段时间后移动设备进入睡眠模式,当我启用或解锁时然后,设备观察到,当设备的方向改变时,应用程序显示由用户填充的内容被清理并且内容恢复。先生,请在此事先帮助我。我还绑定了onCretae方法的源代码。

@覆盖     public void onCreate(Bundle savedInstanceState){         super.onCreate(savedInstanceState);         尝试{

    setContentView(R.layout.main);
    ListView lstMain = (ListView) findViewById(R.id.lstMain);
    btnSetting =(Button)findViewById(R.id.btnSetting);
    btnCheck = (Button)findViewById(R.id.btnCheckStatus);
    btnabout = (Button)findViewById(R.id.btnabout);
    imgUserAdmin = (ImageView)findViewById(R.id.imgUserAdmin);
    btnCheck.setOnClickListener(buttonhandler);
    btnSetting.setOnClickListener(buttonhandler);
    btnExit = (Button)findViewById(R.id.btnExit);
    btnLocation = (Button)findViewById(R.id.btnAddSelLocation);
    btnLocation.setOnClickListener(buttonhandler);
    btnExit.setOnClickListener(buttonhandler);        
    startService(new Intent(this,SmsService.class));
    IntentFilter filter = new IntentFilter(ConstantClass.SMS_RECEIVED);
    registerReceiver(smsSend.sms_send,smsSend.getSentIntentFilter());
    registerReceiver(smsSend.sms_delivered,smsSend.getDeliveredFilter());
    registerReceiver(receivedSms,filter);
   lstMain.setOnItemClickListener(lstMainClick);

    dba.Open();
    String str = "SELECT " + DataBaseAdapter.Key_UserID + " FROM " + ConstantClass.dbName[0] + " WHERE " +
    DataBaseAdapter.Key_MBID + " = ?";
     id = dba.CurrentWorkingCoordinator(DataBaseAdapter.Key_SendCoord, 1);
     if(!Integer.toString(id).equals(ConstantClass.isCrdDiffer))
         ConstantClass.isAuditrequestSend=true;
     if(ConstantClass.isAuditrequestSend==false)
        btnCheck.setText("Checking..");
    String c = null;
    if(id!=0){
    Cursor admin =dba.ExecuteSelect(str, id);
    if (admin!=null)
        admin.moveToFirst();
    if(admin.getCount()>0){
         c = admin.getString(admin.getColumnIndex(DataBaseAdapter.Key_UserID));
        if(c.equals("A")){
            ConstantClass.has_authority = "A";
            imgUserAdmin.setImageResource(R.drawable.admin);
        }else
        imgUserAdmin.setImageResource(R.drawable.admingreen);
    }
    if(ConstantClass.SelectCord.equals("All")){
        btnCheck.setEnabled(false);
        btnSetting.setEnabled(false);
        String dev="000000";
        curMain = dba.SelectDeviceOnId(DataBaseAdapter.Key_DevID, dev);
        /*cursor = dba.getCoord(1);
        if (cursor.getCount()>0){
            cursor.moveToFirst();
            ConstantClass.address = cursor.getString(cursor.getColumnIndex(DataBaseAdapter.Key_MbNo)).toString();
        }*/
        startManagingCursor(curMain);
        if(curMain.getCount()>0){
            curMain.moveToFirst();
            adpt = new customCursorAdapter(this,curMain);  
            lstMain.setAdapter(adpt);           
        }

    }else{
    curMain = dba.SelFromDeviceStorage(DataBaseAdapter.Key_DevCoordId,id); 
    cursor = dba.getCoord(1);
    if (cursor.getCount()>0){
        cursor.moveToFirst();
        ConstantClass.address = cursor.getString(cursor.getColumnIndex(DataBaseAdapter.Key_MbNo)).toString();
    }
    startManagingCursor(curMain);
    if(curMain.getCount()>0){
        curMain.moveToFirst();
        adpt = new customCursorAdapter(this,curMain);  
        lstMain.setAdapter(adpt);           
            }
        }
    }
    }catch(Exception ex){
        dlg = new ExceptionDialog(this,"Zigbee Activity",ex.getMessage());
        dlg.show();
    }


}

1 个答案:

答案 0 :(得分:0)

将此行添加到您的清单中的活动中。

android:configChanges="orientation">

另请阅读Greg的链接:-p