【发布时间】:2017-06-09 17:31:09
【问题描述】:
我目前正在开发一个应用程序,以衡量应用程序在启动时间方面相对于基于 Web 的应用程序的优势。我决定使用意图来启动 Youtube 应用程序和 Web 界面,但我目前很难测量启动时间。顺便说一句,我是个新手。
package com.example.thabo.app_optimization;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
String TestVid_ID = "giYeaKsXnsI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void watchYoutubeVideo(String id, String runType){
Intent appIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("vnd.youtube:" + id));
Intent webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=" + id));
if (runType == "app") {
startActivity(appIntent);}
else
startActivity(webIntent);
display();
}
/**
* Method to initialize the application
*/
public void RUN_APP(View view) {
watchYoutubeVideo(TestVid_ID, "app");
}
public void RUN_WEB(View view){
watchYoutubeVideo(TestVid_ID, "web");
}
/**
* Method to display the name of the current activity onscreen
* */
private void display() {
TextView Activity = (TextView) findViewById(
R.id.Activity);
Activity.setText(this.getClass().getSimpleName());
}
}
【问题讨论】: