首页 > 解决方案 > 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 与其他活动位于另一个文件夹中。

在此处输入图像描述

标签: javaandroidkotlin

解决方案


推荐阅读