我需要在MainActivity类中实例化一个类。因此,我使用了在类上定义的构造函数,但问题是它包含了一些我不知道如何实例化的参数。
这是类构造函数:(请参阅注释)
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 ??
}
答案 0 :(得分:1)
new FallbackLocationTracker(this,ProviderLocationTracker.ProviderType.NETWORK);