2012-04-19 126 views
-1

我使用身份验证进入页面,经过身份验证后,只有用户进入页面。我为onbackpressed()编写了一个代码,但它不起作用。这里DatabaseDemo和Login是两个类。当我按下后退按钮登录类与用户名和密码显示。onbackpressed()方法崩溃

public class DatabaseDemo extends TabActivity { 
    DatabaseHelper dbHelper; 
    GridView grid; 
    TextView txtTest; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     SetupTabs(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     menu.add(1, 1, 1, "Add Employee"); 
     return true; 
    } 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 
     switch (item.getItemId()) 
     { 
     //Add employee 
     case 1: 
      Intent addIntent=new Intent(this,AddEmployee.class); 
      startActivity(addIntent); 
      break; 
     } 
     super.onOptionsItemSelected(item); 
     return false; 
    } 
    void SetupTabs() 
    { 
     TabHost host=getTabHost(); 
     TabHost.TabSpec spec=host.newTabSpec("tag1"); 
     Intent in1=new Intent(this, AddEmployee.class); 
     spec.setIndicator("Add Employee"); 
     spec.setContent(in1); 

     TabHost.TabSpec spec2=host.newTabSpec("tag2"); 
     Intent in2=new Intent(this, GridList.class); 

     spec2.setIndicator("Employees"); 
     spec2.setContent(in2); 

     host.addTab(spec); 
     host.addTab(spec2); 
    } 
    @Override 
    public void onBackPressed() 
    { 
     Intent i = new Intent(DatabaseDemo.this, Login.class); 
     startActivity(i); 
    } 
} 
+2

发布你的logcat输出,所以我们知道你得到了什么错误。 – 2012-04-19 18:24:19

回答

0

你有它开始压在后面的登录,所以如果它的崩溃,则可能是您的登录活动不对劲更可能,而不是在这里。