You will need to pass off a Context, even the ContentResolver
class needs a valid context to be instantiated.
Simplest way is as an argument to the method:
public void test(Context context) throws Exception {
Uri uri = SuspiciousActivityTable.CONTENT_URI;
context.getContentResolver().update(uri, values2, where,new String[]{"Null"});
}
And to call: (assuming that the class that contains test
is instantiated and your Activity's name is MyActivity
<- Replace with the Activity
name you're calling test()
from)
try{
sendInformationInstanceVariable.test (MyActivity.this);
}
catch (Exception e)
{
e.printStackTrace();
}
MyActivity.this
can be shortened to just this
if you're not calling test()
from inside an anonymous inner class.
Also, if your class really doesn't have a good reason to be instantiated, consider making test()
a static
method, like this:
public static void test(Context context) throws Exception {
Uri uri = SuspiciousActivityTable.CONTENT_URI;
context.getContentResolver().update(uri, values2, where,new String[]{"Null"});
}
Then from your Activity
, you call this method without needing an instance:
try{
sendInformation.test (MyActivity.this);
}
catch (Exception e)
{
e.printStackTrace();
}
Lastly, throwing Exception
is bad practice, do don't do it without good reason and if you do have a good reason, be as specific as possible.