Reputation: 2402
i'm creating an App preferences class that i can put functions in that i use app wide such as a check internet connection function. what i'm trying to do is import the class into my activity the run one its functions in the on create. does anyone know how to do this?
heres what i've got so far
import android.app.Activity;
import android.os.Bundle;
import co.myapp.AppPreferences;
public class Loading extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lo_loading);
AppPreferences.class.checkInternet()
}
}
heres my AppPreferences.java
public class AppPreferences {
public void checkInternet(){
Log.v("Pref", "checking internet");
}
}
Upvotes: 1
Views: 1777
Reputation: 13541
You have to instantiate an object of type Apppreference in order to access its methods (unless they are static)
Upvotes: 0
Reputation:
checkInternet()
is non-static you need an instance of AppPreferences
in your activity and use the method on this instance:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lo_loading);
AppPreferences appPrefs = new AppPreferences()
appPrefs.checkInternet()
}
Another solution is to make checkInternet()
static
.
Upvotes: 3