按主页按钮然后从最近列表中按应用程序后,音乐无法恢复。请对给出的代码进行必要的更改。
public class MainActivity extends AppCompatActivity {
@Override
protected void onPause() {
super.onPause();
mySound.release();
}
@Override
protected void onResume() {
super.onResume();
if(mySound != null)
mySound.start();
}
MediaPlayer mySound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySound = MediaPlayer.create(MainActivity.this,R.raw.sleep);
mySound.start();
mySound.setLooping(true);
}
}
答案 0 :(得分:1)
首先看一下How to ask a Good Question on SO。
其次请仔细阅读How to Add code in SO。
现在回答你的问题。问题出在Activity
的{{1}}方法中,只需将其更改为。
onPause()
只有在@Override
protected void onPause() {
super.onPause();
if (mySound != null)
mySound.pause();
}
不再需要时才调用release()。来自Android docs
void release()
释放与此MediaPlayer对象关联的资源。它是 当你完成使用时,我们认为这是一种很好的做法 MediaPlayer。
所以改为使用MediaPlayer
void pause()
暂停播放。调用start()恢复。
图表代表的是有效的状态,确定使用MediaPlayer
对象。
答案 1 :(得分:-1)
$ aws rds describe-db-parameters --db-parameter-group-name default.mysql5.6 --query 'Parameters[*].ParameterName'
[
"allow-suspicious-udfs",
"auto_increment_increment",
"auto_increment_offset",
"autocommit",
"automatic_sp_privileges",
"back_log",
"basedir",
"binlog_cache_size",
"binlog_checksum",
"binlog_error_action",
"binlog_format",
"binlog_max_flush_queue_time",
"binlog_order_commits",
"binlog_row_image",
"binlog_rows_query_log_events",
"binlog_stmt_cache_size",
"binlogging_impossible_mode",
"bulk_insert_buffer_size",
"character-set-client-handshake",
"character_set_client",
"character_set_connection",
"character_set_database",
"character_set_filesystem",
"character_set_results",
"character_set_server",
"collation_connection",
"collation_server",
"completion_type",
"concurrent_insert",
"connect_timeout",
"core-file",
"datadir",
"default_storage_engine",
"default_time_zone",
"default_tmp_storage_engine",
"default_week_format",
"delay_key_write",
"delayed_insert_limit",
"delayed_insert_timeout",
"delayed_queue_size",
"div_precision_increment",
"end_markers_in_json",
"enforce_gtid_consistency",
"eq_range_index_dive_limit",
"event_scheduler",
"explicit_defaults_for_timestamp",
"flush",
"flush_time",
"ft_boolean_syntax",
"ft_max_word_len",
"ft_min_word_len",
"ft_query_expansion_limit",
"ft_stopword_file",
"general_log",
"general_log_file",
"group_concat_max_len",
"gtid-mode",
"host_cache_size",
"init_connect",
"innodb_adaptive_flushing",
"innodb_adaptive_flushing_lwm",
"innodb_adaptive_hash_index",
"innodb_adaptive_max_sleep_delay",
"innodb_autoextend_increment",
"innodb_autoinc_lock_mode",
"innodb_buffer_pool_dump_at_shutdown",
"innodb_buffer_pool_dump_now",
"innodb_buffer_pool_filename",
"innodb_buffer_pool_instances",
"innodb_buffer_pool_load_abort",
"innodb_buffer_pool_load_at_startup",
"innodb_buffer_pool_load_now",
"innodb_buffer_pool_size",
"innodb_change_buffer_max_size",
"innodb_change_buffering",
"innodb_checksum_algorithm",
"innodb_cmp_per_index_enabled",
"innodb_commit_concurrency",
"innodb_compression_failure_threshold_pct",
"innodb_compression_level",
"innodb_compression_pad_pct_max",
"innodb_concurrency_tickets",
"innodb_data_home_dir",
"innodb_fast_shutdown",
"innodb_file_format",
"innodb_file_per_table",
"innodb_flush_log_at_timeout",
"innodb_flush_log_at_trx_commit",
"innodb_flush_method",
"innodb_flush_neighbors",
"innodb_flushing_avg_loops",
"innodb_force_load_corrupted",
"innodb_ft_aux_table",
"innodb_ft_cache_size",
"innodb_ft_enable_stopword",
"innodb_ft_max_token_size",
"innodb_ft_min_token_size",
"innodb_ft_num_word_optimize",
"innodb_ft_result_cache_limit",
"innodb_ft_server_stopword_table",
"innodb_ft_sort_pll_degree",
"innodb_ft_user_stopword_table",
"innodb_io_capacity",
"innodb_io_capacity_max",
"innodb_large_prefix",
"innodb_lock_wait_timeout",
"innodb_log_buffer_size",
"innodb_log_compressed_pages",
"innodb_log_file_size",
"innodb_log_group_home_dir",
"innodb_lru_scan_depth",
"innodb_max_dirty_pages_pct",
"innodb_max_purge_lag",
"innodb_max_purge_lag_delay",
"innodb_monitor_disable",
"innodb_monitor_enable",
"innodb_monitor_reset",
"innodb_monitor_reset_all",
"innodb_old_blocks_pct",
"innodb_old_blocks_time",
"innodb_online_alter_log_max_size",
"innodb_open_files",
"innodb_optimize_fulltext_only",
"innodb_page_size",
"innodb_print_all_deadlocks",
"innodb_purge_batch_size",
"innodb_purge_threads",
"innodb_random_read_ahead",
"innodb_read_ahead_threshold",
"innodb_read_io_threads",
"innodb_read_only",
"innodb_replication_delay",
"innodb_rollback_on_timeout",
"innodb_rollback_segments",
"innodb_sort_buffer_size",
"innodb_spin_wait_delay",
"innodb_stats_auto_recalc",
"innodb_stats_method",
"innodb_stats_on_metadata",
"innodb_stats_persistent",
"innodb_stats_persistent_sample_pages",
"innodb_stats_transient_sample_pages",
"innodb_strict_mode",
"innodb_support_xa",
"innodb_sync_array_size",
"innodb_sync_spin_loops",
"innodb_table_locks",
"innodb_thread_concurrency",
"innodb_thread_sleep_delay",
"innodb_undo_directory",
"innodb_undo_logs",
"innodb_undo_tablespaces",
"innodb_use_native_aio",
"innodb_write_io_threads",
"interactive_timeout",
"join_buffer_size",
"keep_files_on_create",
"key_buffer_size",
"key_cache_age_threshold",
"key_cache_block_size",
"key_cache_division_limit",
"lc_time_names",
"local_infile",
"lock_wait_timeout",
"log-bin",
"log_bin_trust_function_creators",
"log_bin_use_v1_row_events",
"log_error",
"log_output",
"log_queries_not_using_indexes",
"log_slave_updates",
"log_slow_admin_statements",
"log_slow_slave_statements",
"log_throttle_queries_not_using_indexes",
"log_warnings",
"long_query_time",
"low_priority_updates",
"lower_case_table_names",
"master-info-repository",
"master_verify_checksum",
"max_allowed_packet",
"max_binlog_cache_size",
"max_binlog_size",
"max_binlog_stmt_cache_size",
"max_connect_errors",
"max_connections",
"max_delayed_threads",
"max_error_count",
"max_heap_table_size",
"max_insert_delayed_threads",
"max_join_size",
"max_length_for_sort_data",
"max_prepared_stmt_count",
"max_seeks_for_key",
"max_sort_length",
"max_sp_recursion_depth",
"max_tmp_tables",
"max_user_connections",
"max_write_lock_count",
"metadata_locks_cache_size",
"min_examined_row_limit",
"myisam_data_pointer_size",
"myisam_max_sort_file_size",
"myisam_mmap_size",
"myisam_sort_buffer_size",
"myisam_stats_method",
"myisam_use_mmap",
"net_buffer_length",
"net_read_timeout",
"net_retry_count",
"net_write_timeout",
"old-style-user-limits",
"old_passwords",
"optimizer_prune_level",
"optimizer_search_depth",
"optimizer_switch",
"optimizer_trace",
"optimizer_trace_features",
"optimizer_trace_limit",
"optimizer_trace_max_mem_size",
"optimizer_trace_offset",
"performance_schema",
"performance_schema_accounts_size",
"performance_schema_digests_size",
"performance_schema_events_stages_history_long_size",
"performance_schema_events_stages_history_size",
"performance_schema_events_statements_history_long_size",
"performance_schema_events_statements_history_size",
"performance_schema_events_waits_history_long_size",
"performance_schema_events_waits_history_size",
"performance_schema_hosts_size",
"performance_schema_max_cond_classes",
"performance_schema_max_cond_instances",
"performance_schema_max_file_classes",
"performance_schema_max_file_handles",
"performance_schema_max_file_instances",
"performance_schema_max_mutex_classes",
"performance_schema_max_mutex_instances",
"performance_schema_max_rwlock_classes",
"performance_schema_max_rwlock_instances",
"performance_schema_max_socket_classes",
"performance_schema_max_socket_instances",
"performance_schema_max_stage_classes",
"performance_schema_max_statement_classes",
"performance_schema_max_table_handles",
"performance_schema_max_table_instances",
"performance_schema_max_thread_classes",
"performance_schema_max_thread_instances",
"performance_schema_session_connect_attrs_size",
"performance_schema_setup_actors_size",
"performance_schema_setup_objects_size",
"performance_schema_users_size",
"pid_file",
"plugin_dir",
"port",
"preload_buffer_size",
"profiling_history_size",
"query_alloc_block_size",
"query_cache_limit",
"query_cache_min_res_unit",
"query_cache_size",
"query_cache_type",
"query_cache_wlock_invalidate",
"query_prealloc_size",
"range_alloc_block_size",
"read_buffer_size",
"read_only",
"read_rnd_buffer_size",
"relay-log",
"relay_log_info_repository",
"relay_log_recovery",
"safe-user-create",
"secure_auth",
"secure_file_priv",
"server_id",
"simplified_binlog_gtid_recovery",
"skip-character-set-client-handshake",
"skip-slave-start",
"skip_external_locking",
"skip_name_resolve",
"skip_show_database",
"slave_checkpoint_group",
"slave_checkpoint_period",
"slave_parallel_workers",
"slave_pending_jobs_size_max",
"slave_sql_verify_checksum",
"slave_type_conversions",
"slow_launch_time",
"slow_query_log",
"slow_query_log_file",
"socket",
"sort_buffer_size",
"sql_mode",
"sql_select_limit",
"stored_program_cache",
"sync_binlog",
"sync_frm",
"sync_master_info",
"sync_relay_log",
"sync_relay_log_info",
"sysdate-is-now",
"table_definition_cache",
"table_open_cache",
"table_open_cache_instances",
"temp-pool",
"thread_cache_size",
"thread_stack",
"time_zone",
"timed_mutexes",
"tmp_table_size",
"tmpdir",
"transaction_alloc_block_size",
"transaction_prealloc_size",
"tx_isolation",
"updatable_views_with_limit",
"validate-password",
"validate_password_dictionary_file",
"validate_password_length",
"validate_password_mixed_case_count",
"validate_password_number_count",
"validate_password_policy",
"validate_password_special_char_count",
"wait_timeout"
]