【发布时间】:2015-06-16 23:10:46
【问题描述】:
我需要在 MainActivity 类中实例化一个类。因此我使用了在该类上定义的构造函数,但问题是它包含一些我不知道如何实例化的参数。
这是类构造函数:(请参阅 cmets)
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 ??
}
【问题讨论】:
标签: android constructor instantiation