views:

15

answers:

1

I am using Gamelogic class which implements no one (just object to be honest )

and i want from him to set a data base where the game screen ask the logic questions and the last ask the sql question without all the Context usage , just to keep it simple .

is it possible ? if not what is the alternative , can someone show me little example i am lost and the notepad example doest help

thanx yoav.

A: 

You HAVE to use a Context in that case. But you are lucky, all activities are Contexts so what you have to do is passing a reference of your activity to the Gamelogic class. For instance, you can pass it as an argument to its constructor:

public class Gamelogic{
    private Context context;
    public Gamelogic(Context context){
        this.context = context;
        // do what ever you want with the context object
    }
    // more complex logic here
}

On your activity:

public class YourActivity extends Activity{

    // foo bar baz blablablabla

    public void someWhereOnYourActitity(){
        new Gamelogic(YourActivity.this);
    }
}
Cristian
does it makes a difference if i send 1.this.getApplicationContext()OR2.YourActivity.this?
yoav.str
Actually no... they reference the same context.
Cristian