测量android意图运行应用程序所需的时间

时间:2017-06-09 17:31:10

标签: android android-intent

我目前正在开发一款应用程序,以衡量应用程序启动时间优于其基于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());
    }

}

1 个答案:

答案 0 :(得分:0)

要做到这一点,我建议你创建一个后台服务,然后你开始一些"时钟"那里测量时间 - >> Android - To measure the time between the two button clicks!要检查进程是否已打开(然后停止"时钟"),您必须在android(List of All running processes in Android

上迭代整个进程列表