我的一个Android活动运行得很糟糕

时间:2017-08-03 16:10:50

标签: java android webview

您好亲爱的StackOverflow社区!!! 在开发我最近的应用项目时,我在调试应用时发现了一些问题。在我的项目中,我想通过2个活动传递一个数据元素。在我的应用程序中选择WatchingActivity之前,一切看起来都很好(没有错误或其他东西)。它不显示webview,但只显示白色空白,而PartActivity中应该选择视频。请帮忙!!!!

public class MainActivity extends AppCompatActivity {
    String clipname;
    ImageView ka;
    ImageView jb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ka = (ImageView) findViewById(R.id.imageView1);
        jb = (ImageView) findViewById(R.id.imageView2);
    }

    public void imageView1Clicked(View view) {
        // method that is signed in layout file to be called by clicking on imageView1
        clipname="Kendra's Adventure";
        Intent mainintent = new Intent(this, ChooseAPartActivity.class);
        mainintent.putExtra("CLIP", clipname);
        startActivity(mainintent);
    }

    public void imageView2Clicked(View view) {
        clipname="Johhny Big";
        Intent mainintent = new Intent(this, ChooseAPartActivity.class);
        mainintent.putExtra("CLIP", clipname);
        startActivity(mainintent);

    }
}

public class ChooseAPartActivity extends AppCompatActivity {
    TextView title;
    TextView part1;
    TextView part2;
    TextView part3;
    TextView part4;
    TextView part5;
    TextView part6;
    String videoname;
    String partnumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_a_part);
        title.findViewById(R.id.textView);

        title.findViewById(R.id.textView);

        Intent mainintent = getIntent();

        String clipname = mainintent.getStringExtra("CLIP");

        title.setText(clipname);
        videoname = clipname;
    }

    public void partone (View view) { 
    //method assigned to textview in layout file
        partnumber = "one";
        Intent partintent = new Intent(this, WatchingActivity.class);
        partintent.putExtra("PART", videoname);
        partintent.putExtra("NUMBER", partnumber);
        startActivity(partintent);
    }
    public void parttwo (View view) {
        partnumber = "two";
        Intent partintent = new Intent(this, WatchingActivity.class);
        partintent.putExtra("PART", videoname);
        partintent.putExtra("NUMBER", partnumber);
        startActivity(partintent);
    }
    public void partthree (View view) {
        partnumber = "three";
        Intent partintent = new Intent(this, WatchingActivity.class);
        partintent.putExtra("PART", videoname);
        partintent.putExtra("NUMBER", partnumber);
        startActivity(partintent);
    }
    public void partfour (View view) {
        partnumber = "four";
        Intent partintent = new Intent(this, WatchingActivity.class);
        partintent.putExtra("PART", videoname);
        partintent.putExtra("NUMBER", partnumber);
        startActivity(partintent);
    }
    public void partfive (View view) {
        partnumber = "five";
        Intent partintent = new Intent(this, WatchingActivity.class);
        partintent.putExtra("PART", videoname);
        partintent.putExtra("NUMBER", partnumber);
        startActivity(partintent);
    }
    public void partsix (View view) {
        partnumber = "six";
        Intent partintent = new Intent(this, WatchingActivity.class);
        partintent.putExtra("PART", videoname);
        partintent.putExtra("NUMBER", partnumber);
        startActivity(partintent);
    }
}
public class WatchingActivity extends AppCompatActivity {

    String clipkey;
    WebView screen;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_watching);
Intent sceneintent = getIntent();

        String videoname = partintent.getStringExtra("PART");
        String partnumber = sceneintent.getStringExtra("NUMBER");

        if(videoname == "Kendra's Adventure"){
            if(partnumber == "one"){
         clipkey = "<iframe width=\"95%\" height=\"95%\" src=\"links work fine i tried it many times so its not that\" frameborder=\"0\" allowfullscreen></iframe>";
            }
        }
        else if(videoname == "Johnny Big"){
            if(partnumber == "one") {
                clipkey = "<iframe width=\"95%\" height=\"95%\" src=\"\" frameborder=\"0\" allowfullscreen></iframe>";
            }
            else if(partnumber == "two"){
                clipkey = "<iframe width=\"95%\" height=\"95%\" src=\"\" frameborder=\"0\" allowfullscreen></iframe>";

            }
        }
        screen=(WebView)findViewById(R.id.webView);
        screen.getSettings().setJavaScriptEnabled(true);
        String myvideokey = clipkey;
        screen.loadData(myvideokey, "text/html", "utf-8");
        screen.setWebChromeClient(new WebChromeClient(){
        });
}
}

1 个答案:

答案 0 :(得分:0)

String videoname = partintent.getStringExtra("PART");

WatchingActivity中该行是否正常?没有partintent字段或其他东西。

在同一个类文件中定义所有活动并不是一个好主意。