开发者

Android code starting from ContentProvider class rather than Main class

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 Data开发者_如何学运维baseHelper(Context context) {

        super(context, DB_NAME, null, 1);

        this.myContext = context;

    }


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 :)


Thanks for that info, a debugger won't help for manifest problems and you can't put log entries or toast in the manifest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜