Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Start Activity,Stop Activity and Suspend Activity

Shulou Source: shulou.com Published: 2022-06-01 01:06:05 09月30日 Update

Most people do not understand the knowledge points of this article "how to use Start Activity,Stop Activity and Suspend Activity", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Start Activity,Stop Activity and Suspend Activity" article.

Start Activity;Stop Activity and Suspend Activity are used to play music, stop music and pause playback, respectively.

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

}

}

}

The above is about the content of this article on "how to use Start Activity,Stop Activity and Suspend Activity". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Content articles knowledge articles music value most of them that is more steps knowledge points industry information information channels channels help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Shulou Tech Info Microsoft Xiaomi