在android地图中创建线程

时间:2012-10-20 03:55:51

标签: android multithreading google-maps

我正在尝试实施Android应用, 在主要活动中它显示谷歌地图,我试图在同一布局上实现视频视图。 因此,在主地图活动中(当地图显示时)我试图实现一个线程,该线程将同时在地图视图下方调用视频视图活动(进行录制)。

这可能吗? 因为我得到了很多错误。 请任何人帮助我..? 感谢

公共类MainActivity扩展MapActivity实现Runnable {

private MapView mapView;
private MyLocationOverlay myLocationOverlay;
private Button playerbtn;//button to start player
private Button recorderbtn;//button for recorder
private VideoView mVideoView;
private Uri mVideoUri;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mVideoView = (VideoView) findViewById(R.id.videoview);
    playerbtn= (Button)findViewById(R.id.playback);
    recorderbtn = (Button)findViewById(R.id.recording);

    // main.xml contains a MapView
    setContentView(R.layout.main); 

    // extract MapView from layout
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    // create an overlay that shows our current location
    myLocationOverlay = new FixedMyLocationOverlay(this, mapView);

    // add this overlay to the MapView and refresh it
    mapView.getOverlays().add(myLocationOverlay);
    mapView.postInvalidate();

    // call convenience method that zooms map on our location
    zoomToMyLocation();



}

//--videoview

public void recordingListner(View view) {

    Thread toRun = new Thread()
       {
              public void run()
              {

                 final Intent intent = new Intent(MainActivity.this, VideoRecorder.class);
                handleCameraVideo(intent);
                startActivity(intent);    

              }
       };
       toRun.start(); 

}

private void handleCameraVideo(Intent intent) {
    mVideoUri = intent.getData();
    mVideoView.setVideoURI(mVideoUri);
    mVideoView.setVisibility(View.VISIBLE);
}

1 个答案:

答案 0 :(得分:0)

setContentView(R.layout.main);之后将super.onCreate(savedInstanceState);移至右侧。在调用findViewById之前,必须调用setContentView。