在 Android 中使用 class 构造函数
Use a class constructor in Android
我需要在 MainActivity class 中实例化一个 class 。因此我使用了 class 上定义的构造函数,但问题是它包含一些我不知道如何使用的参数实例化。
这是 class 构造函数:(请参阅评论)
public class FallbackLocationTracker implements LocationTracker, LocationTracker.LocationUpdateListener {
private boolean isRunning;
private ProviderLocationTracker gps;
private ProviderLocationTracker net;
private LocationUpdateListener listener;
Location lastLoc;
long lastTime;
public FallbackLocationTracker(Context context, ProviderLocationTracker.ProviderType type) {
gps = new ProviderLocationTracker(context, ProviderLocationTracker.ProviderType.GPS);
net = new ProviderLocationTracker(context, ProviderLocationTracker.ProviderType.NETWORK);
}
这就是我在 Mainactivity 中所做的:
public class MainActivity extends Activity {
GPSTracker gps;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gps = new FallbackLocationTracker( );//What should i do here to make use of the class and all the methods ??
}
new FallbackLocationTracker(this,ProviderLocationTracker.ProviderType.NETWORK);
我需要在 MainActivity class 中实例化一个 class 。因此我使用了 class 上定义的构造函数,但问题是它包含一些我不知道如何使用的参数实例化。
这是 class 构造函数:(请参阅评论)
public class FallbackLocationTracker implements LocationTracker, LocationTracker.LocationUpdateListener {
private boolean isRunning;
private ProviderLocationTracker gps;
private ProviderLocationTracker net;
private LocationUpdateListener listener;
Location lastLoc;
long lastTime;
public FallbackLocationTracker(Context context, ProviderLocationTracker.ProviderType type) {
gps = new ProviderLocationTracker(context, ProviderLocationTracker.ProviderType.GPS);
net = new ProviderLocationTracker(context, ProviderLocationTracker.ProviderType.NETWORK);
}
这就是我在 Mainactivity 中所做的:
public class MainActivity extends Activity {
GPSTracker gps;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gps = new FallbackLocationTracker( );//What should i do here to make use of the class and all the methods ??
}
new FallbackLocationTracker(this,ProviderLocationTracker.ProviderType.NETWORK);