java - Android:为什么按下按钮时我的活动没有出现?
问题描述
我是android开发的新手。我正在学习如何在 Kotlin 中制作应用程序。在我的 MainActivity.kt 上,我有以下代码:
recordBtn.setOnClickListener{
val intent = Intent(this, com.example.testapp.data.RecordActivity::class.java)
startActivity(intent)
}
出于某种原因,我可以使用屏幕上的更新密码和注销按钮,但是当我按下记录按钮转到 activity_record.xml 时,我只会得到一个空白的白色屏幕。这是我的 RecordActivity.kt 的 onCreate:
@RequiresApi(Build.VERSION_CODES.M)
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
setContentView(R.layout.activity_record)
Log.e("Record Activity","Reached the onCreate of the RecordActivity")
requestPermissions(permissions, REQUEST_RECORD_AUDIO_PERMISSION)
// recordbtn = findViewById(R.id.recordbtn)
// playbtn = findViewById(R.id.playbtn)
recordbtn = RecordButton(this)
playbtn = PlayButton(this)
filename = "${externalCacheDir?.absolutePath}/recording.mp3"
mr = MediaRecorder()
mr?.setAudioSource(MediaRecorder.AudioSource.MIC)
mr?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
mr?.setOutputFile(filename)
mr?.setAudioEncoder(3) //AAC; need to review what the best choice here is.
mr?.prepare()
}
我觉得问题可能是我的 RecordActivity.kt 与其他活动位于另一个文件夹中。
解决方案
推荐阅读
- python - 使用 POST 请求提交表单后出现错误 404
- c# - 安全问题 AspNetCore Identity
- c# - C# winforms 图形超大
- java - 使用 JUNIT5 运行 Cucumber 功能文件时无法过滤它们
- python - 在正则表达式上转换 TRIM
- pandas - pandas groupby.apply 0.23.4 和 0.24.2 之间的差异与深拷贝
- sql-server - SQL Server SCOPE_IDENTITY() 与 @@IDENTITY
- python - 如何使用带有 Python 的 Appium 单击具有相同类的多个按钮
- java - 如何在从 Python 3.6 到 Java 1.8 JavaCV 的算法转换中找到轮廓
- jquery - 使用 AJAX 和 jQuery 从 Perl 程序中获取数据