StartActivity,StopActivity和SuspendActivity怎么用

这篇“Start Activity,Stop Activity和Suspend Activity怎么用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Start Activity,Stop Activity和Suspend Activity怎么用”文章吧。

成都创新互联公司专注于烟台企业网站建设,成都响应式网站建设,商城网站建设。烟台网站建设公司,为烟台等地区提供建站服务。全流程按需网站设计,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

Start Activity;Stop Activity 和 Suspend Activity分别用来播放音乐,停止播放音乐和暂停播放。

package mth.android;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class AndroidActivity extends Activity implements View.OnClickListener {
    // Define a media player
 private MediaPlayer mediaPlayer = null;
 private int curPos = 0;
 
 /** Called when the activity is first created. */ 
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //final View textDisplayer = this.findViewById(R.id.displayText);
        //final TextView textDisplayer = (TextView) this.findViewById(R.id.displayText);
       
        Button startActivityButton = (Button)this.findViewById(R.id.startAndroidActivity);
        startActivityButton.setOnClickListener(this);
       
        Button stopActivityButton = (Button)this.findViewById(R.id.stopAndroidActivity);
        stopActivityButton.setOnClickListener(this);
       
        Button suspendActivityButton = (Button)this.findViewById(R.id.suspendAndroidActivity);
        suspendActivityButton.setOnClickListener(this);
        /*
        Button startActivityButton = (Button)this.findViewById(R.id.startAndroidActivity);
        startActivityButton.setOnClickListener(new OnClickListener(){

   public void onClick(View v) {
    // TODO Auto-generated method stub
    display(textDisplayer);
   }
        });
        */
       
        /*
        View startActivityButton = this.findViewById(R.id.startAndroidActivity);
      
        startActivityButton.setOnClickListener(new View.OnClickListener(){
         public void onClick(View v) {
    // TODO Auto-generated method stub
          textDisplayer.setText("Hello World");
    textDisplayer.setBackgroundColor(0xFFFFFFFF);
   }
        }
        );
        */
        /*
        TextView text = new TextView(this);
        text.setText("Hello World");
        setContentView(text);
        */
       
       
       
    }
   
    public void display(TextView tv)
    {
     tv.setText("Hello world");
     tv.setBackgroundColor(0xFFFFFF00);
    }

 public void onClick(View v) {
  //int curPos = 0;;
  switch (v.getId())
  {
  case R.id.startAndroidActivity:
   // TODO Auto-generated method stub
   final TextView textDisplayer = (TextView) this.findViewById(R.id.displayText);
   textDisplayer.setText("Hello world");
   textDisplayer.setBackgroundColor(BIND_AUTO_CREATE);
   // Start media player
   mediaPlayer = MediaPlayer.create(this, R.raw.just_one_last_dance);
         mediaPlayer.seekTo(0);
         mediaPlayer.start();
   break;
  case R.id.stopAndroidActivity:
   mediaPlayer.stop();
   break;
  case R.id.suspendAndroidActivity:
   if(true == mediaPlayer.isPlaying())
   {
    curPos = mediaPlayer.getCurrentPosition();
    mediaPlayer.pause();
   }
   else
   {
    mediaPlayer.seekTo(curPos);
    mediaPlayer.start();
   }
   break;
  default:
   break;
  }
 }
}

以上就是关于“Start Activity,Stop Activity和Suspend Activity怎么用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。


文章名称:StartActivity,StopActivity和SuspendActivity怎么用
文章分享:http://myzitong.com/article/ppsdde.html