I have a situation in which I have defined a background activity, which has to insert data into the database. It worked fine for a single scene as the variables defined are not inside any if-else etc. Now I want to reuse the same class for a different query coming from a different activity/fragment. in simple words, I want to do something like this in pseudo-code.
If(scenario==add_user)
{
String name=abc, city=NY;
String mysql_query="........";// add to user table
}
if(scenario==add_item)
{
String item_name;
String mysql_query="........"; // add to item table
}
execute query;
or if there is a better way. It is working when there are no if statement, I know that the variable scopes are the issue, and I have may variable attached to each scenario, which I don't want to define separately as it will make the code too lengthy. I have tried with switch statement and same issue.
Aucun commentaire:
Enregistrer un commentaire