Android 代码从 ContentProvider 类而不是 Main 类开始
昨天我发布了一个类似的问题,关于为什么我的代码从我的内容提供程序类而不是主类开始,我收到了一些反馈,我已经更新了这些反馈,但问题仍然存在,代码从 ContentProvider 类而不是主类开始班级。我已经使用调试器运行了代码,令人费解的是为什么代码在内容提供程序中启动并在上下文阶段传递回主类。我希望在这里寻求一些帮助!
主要的类在这里:
public class MedF1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drug_list);
ListView drugListView;
ArrayAdapter<Drug> aa;
ArrayList<Drug> drugs = new ArrayList<Drug>();
drugListView = (ListView)this.findViewById(R.id.list1);
DrugProvider.DatabaseHelper mDbHelper1 = new DrugProvider.DatabaseHelper(this);
//Creation of the Database here
try {
mDbHelper1.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
mDbHelper1.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
Content Provider类如下。
public class DrugProvider extends ContentProvider {
// publishing the URI for this provider
public static final Uri CONTENT_URI = Uri
.parse("content://com.paad.provider.drug/drugs");
private static final int DRUGS = 1;
private static final int DRUG_ID = 2;
private static final UriMatcher uriMatcher;
// allocating UriMatcher object
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.paad.provider.drug", "drugs", DRUGS);
uriMatcher.addURI("com.paad.provider.drug", "drugs/#", DRUG_ID);
}
// Column names
public static final String KEY_ROWID = "_id";
public static final String KEY_DRUG = "drug";
public static final String KEY_CONTENT = "content";
public static final String KEY_INDICATION = "indication";
public static final String KEY_DOSAGE = "dosage";
public static final String KEY_SPECIALPRECAUTION = "specialprecaution";
// Column indexes
public static final int DRUG_COLUMN = 1;
public static final int CONTENT_COLUMN = 2;
public static final int INDICATION_COLUMN = 3;
public static final int DOSAGE_COLUMN = 4;
public static final int SPECIALPRECAUTION_COLUMN = 5;
// private DatabaseHelper mDbHelper;
// private SQLiteDatabase mDb;
private static String DB_PATH = "data/data/com.paad.MedF1/databases/";
private static String DB_NAME = "data";
private static final int DATABASE_VERSION = 1;
private static final String DRUG_TABLE = "drugs";
public static SQLiteDatabase myDataBase;
// Creation of the database and its basic parameters
public static class DatabaseHelper extends SQLiteOpenHelper {
public final Context myContext;
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}
Yesterday I posted a similar question on why my code started on my content provider class rather than the main class and I've gotten some feedback which I've updated but the problem still remains where the code starts with the ContentProvider class rather than the main class. I've run through the code with debugger and its puzzling why the code starts in the Content Provider and passes back to the main class at the Context stage. I hope to solicit some help here !
The main class is here:
public class MedF1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drug_list);
ListView drugListView;
ArrayAdapter<Drug> aa;
ArrayList<Drug> drugs = new ArrayList<Drug>();
drugListView = (ListView)this.findViewById(R.id.list1);
DrugProvider.DatabaseHelper mDbHelper1 = new DrugProvider.DatabaseHelper(this);
//Creation of the Database here
try {
mDbHelper1.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
mDbHelper1.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
The Content Provider class is as follows.
public class DrugProvider extends ContentProvider {
// publishing the URI for this provider
public static final Uri CONTENT_URI = Uri
.parse("content://com.paad.provider.drug/drugs");
private static final int DRUGS = 1;
private static final int DRUG_ID = 2;
private static final UriMatcher uriMatcher;
// allocating UriMatcher object
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.paad.provider.drug", "drugs", DRUGS);
uriMatcher.addURI("com.paad.provider.drug", "drugs/#", DRUG_ID);
}
// Column names
public static final String KEY_ROWID = "_id";
public static final String KEY_DRUG = "drug";
public static final String KEY_CONTENT = "content";
public static final String KEY_INDICATION = "indication";
public static final String KEY_DOSAGE = "dosage";
public static final String KEY_SPECIALPRECAUTION = "specialprecaution";
// Column indexes
public static final int DRUG_COLUMN = 1;
public static final int CONTENT_COLUMN = 2;
public static final int INDICATION_COLUMN = 3;
public static final int DOSAGE_COLUMN = 4;
public static final int SPECIALPRECAUTION_COLUMN = 5;
// private DatabaseHelper mDbHelper;
// private SQLiteDatabase mDb;
private static String DB_PATH = "data/data/com.paad.MedF1/databases/";
private static String DB_NAME = "data";
private static final int DATABASE_VERSION = 1;
private static final String DRUG_TABLE = "drugs";
public static SQLiteDatabase myDataBase;
// Creation of the database and its basic parameters
public static class DatabaseHelper extends SQLiteOpenHelper {
public final Context myContext;
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿,我发现为什么代码从 ContentProvider 而不是主类开始。这是因为 ContentProvider 扩展附带的实现方法(onCreate)。我重新利用了另一个教程来创建它,但没有真正理解它......这就是原因。是的,任何其他面临问题的人都应该尝试探索内容提供程序类中的 onCreate 方法是否正在影响它 - 这不是明显的问题:)
Hey I've found out why the code started at the ContentProvider rather than the main class. It was because of the implemented method (onCreate) that comes with the extension of the ContentProvider . I repurposed another tutorial to create it without really understanding it ... thats why. yup anyone else facing the problem should try exploring if the onCreate method in the Content provider class is affecting it - its not the manifest problem :)
感谢您提供该信息,调试器无法帮助解决清单问题,并且您无法将日志条目或 toast 放入清单中。
Thanks for that info, a debugger won't help for manifest problems and you can't put log entries or toast in the manifest.