当前位置:编程学习 > wap >>

为什么我的ContentResolver在另一个程序中调用会启动原来的应用程序(附源码)

http://www.devdiv.com/ContentProvider-weblog-65729-11284.html
我照着这个例子打的,在同一个程序中好使,但是我另建了一个应用程序,当我点击按钮时会跳到原来那个应用程序,怎么办 --------------------编程问答-------------------- 帮帮忙啊,谢谢各位了 --------------------编程问答-------------------- 请问以下代码有什么错,为什么一执行就跳到另外一个程序中了呢
package com.example.hwtest1;

import com.example.hwtest1.DatabaseHelper;
import com.example.hwtest1.R;
import com.example.hwtest1.ProviderConst;

import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends Activity {
 private SQLiteDatabase mdb = null;
 private DatabaseHelper helper = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //initDatabase();
        setContentView(R.layout.activity_main);
    }
    private void initDatabase()
    {
     mdb = this.openOrCreateDatabase("dbfile", 0, null);
     String sql_create = "create table test (id int, name TEXT)";
     mdb.execSQL(sql_create);
     helper = new DatabaseHelper(this,"dbfile");
     //mdb = this.openOrCreateDatabase("dbfile", 0, null);
     //String sql_create = "create table test (id int, name TEXT)";
     //mdb.execSQL(sql_create);
     String sql_insert = "insert into test(id, name) values(56, 'namexx')";
     //mdb.execSQL(sql_insert);
     helper.insert(sql_insert);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
      super.onCreateOptionsMenu(menu); 
     menu.add(1, Menu.FIRST +1, 1, "GetName");  
       menu.add(1, Menu.FIRST +2, 2, "Test");
     //getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    private String getName1()
    {
     String name = null;      
     Cursor cur = this.getContentResolver().query(ProviderConst.MY_TEST_URI,new String[]{"id","name"},null, null, null);
     //Cursor cur = managedQuery(ProviderConst.MY_TEST_URI,new String[]{"id","name"},null,null,null);
     if (cur == null)
      return null;
     cur.moveToFirst();
     do
     {
      name = name  + cur.getString(1)+ "\n";      
      
     } while(cur.moveToNext());      
     
     return name;
    }
     
    public boolean onOptionsItemSelected(MenuItem item) {
       // TODO Auto-generated method stub
       super.onOptionsItemSelected(item);
       switch (item.getItemId())
       {
        case Menu.FIRST+ 1:
        {
         TextView tv = (TextView)this.findViewById(R.id.textView1);
         tv.setText(getName1());
         break;
        }
        case Menu.FIRST + 2:
        {
         this.setTitle("Del Item...");
         break;
        }   
       }
       return true;
      }
    
}
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,