if(url!= null)不起作用

时间:2016-01-20 18:50:47

标签: android android-intent

因为如果“url”有信息,我可以有所作为。因为我做得不好而创造。它不起作用

        Bundle bundle = getIntent().getExtras();
    String url = bundle.getString("url");

    if (url != null) {
        emVideoView = (EMVideoView)findViewById(R.id.video_play_activity_video_view);
        emVideoView.setOnPreparedListener(this);
        //For now we just picked an arbitrary item to play.  More can be found at
        //https://archive.org/details/more_animation
        emVideoView.setVideoURI(Uri.parse(url));
    } else{
        Toast.makeText(getBaseContext(), "Not url found!", Toast.LENGTH_SHORT).show();
        MainActivity.this.finish();
    }

2 个答案:

答案 0 :(得分:1)

尝试:

if (!String.IsNullOrEmpty(url)) 

这将确保String.Empty值也不存在,这与字符串为null不同。换句话说:

String s = null;

与:

不同
String s = String.Empty;

答案 1 :(得分:1)

if(url != null)
  if(!url.isEmpty())

此外,当从捆绑中检索项目时,简单的if(bundle.getString("url") != null)也会有所帮助。