千家信息网

Start Activity,Stop Activity和Suspend Activity怎么用

发表于:2025-01-25 作者:千家信息网编辑
千家信息网最后更新 2025年01月25日,这篇"Start Activity,Stop Activity和Suspend Activity怎么用"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴
千家信息网最后更新 2025年01月25日Start Activity,Stop Activity和Suspend Activity怎么用

这篇"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怎么用"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。

0