我有一个变量,我使用onSaveInstanceState成功保存和恢复
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); // the UI component values are saved here.
outState.putDouble("VALUE", liter);
Toast.makeText(this, "Activity state saved", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
但这仅在活动被销毁时才有效.我希望通过覆盖onPause()方法来保存相同的变量,并且当活动不再暂停时返回任何关于如何执行此操作的任何想法都非常感谢
我使用缓冲读取器读取充满信息行的文件.一些较长的文本行扩展为多行,因此缓冲区将其视为新行.每行以';'符号结尾.所以我想知道是否有办法使缓冲读取器读取一行直到它到达';'然后返回整行作为字符串.这是我到目前为止如何使用缓冲读卡器.
String currentLine;
while((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String[] line = currentLine.split(" ");
String fir = line[1];
String las = line[2];
for(int c = 0; c < players.size(); c++){
if(players.get(c).getFirst().equals(fir) && players.get(c).getLast().equals(las) ){
System.out.println(fir + " " + las);
String text2 = currentLine.replaceAll("[.*?]", ".150");
writer.write(text2 + System.getProperty("line.separator"));
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个媒体播放器,但是当选择另一个文件时,它会继续播放旧文件和新文件,因此它会同时播放两个文件,这是我的 onCreate 方法
private MediaPlayer mediaplayer = new MediaPlayer();
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.songplaying);
// Getting Our Extras From Intent
Bundle names = getIntent().getExtras();
// Getting Specific Data
path = names.getString("pathkeyword");
//Start Player
try {
playAudio(path);
} catch (Exception e) {
e.printStackTrace();
Run Code Online (Sandbox Code Playgroud)
}
这是播放音频的方法
private void playAudio(String url) throws Exception{
mediaplayer.release();
mediaplayer.setDataSource(url);
mediaplayer.prepare();
mediaplayer.start();
Run Code Online (Sandbox Code Playgroud) 我有一个服务,它接收一个音频文件并与媒体播放器播放,这就是我打电话给我的服务
private void playAudio(String url) throws Exception{
Intent music = new Intent(this,MusicService.class);
music.putExtra("paths", path);
startService(music);
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务
class MusicService extends Service implements OnCompletionListener {
MediaPlayer mediaPlayer;
String musicFile;
@Override
public void onCreate() {
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnCompletionListener(this);
Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle e = intent.getExtras();
musicFile= e.getString("paths");
try {
mediaPlayer.prepare();
mediaPlayer.setDataSource(musicFile);
} catch (IllegalArgumentException i) {
// TODO Auto-generated catch block
i.printStackTrace();
} catch (IllegalStateException i) {
// TODO …Run Code Online (Sandbox Code Playgroud) 当我使用它上传图像但在上传视频时不起作用时,此表单有效.通过此表单上传视频需要更改哪些内容?
$videoform = "
<form action='' method='post' enctype='multipart/form-data' name='uploadform'>
<input name='video' type='file' id='video' >
<input name='upload' type='submit' id='upload' value=' Upload Video! '>
</form>";
echo $form;
if($_POST['upload'])
{
echo $videoform;
}
if(isset($_POST['upload']))
{
// define the posted file into variables
$name = $_FILES['video']['name'];
$tmp_name = $_FILES['video']['tmp_name'];
$type = $_FILES['video']['type'];
$size = $_FILES['video']['size'];
echo $name;
}
echo "<br /><h5>$cname 's Videos</h5>";
?>
Run Code Online (Sandbox Code Playgroud)