Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

反射执行起来太慢了 #1

Open
congwiny opened this issue May 19, 2020 · 0 comments
Open

反射执行起来太慢了 #1

congwiny opened this issue May 19, 2020 · 0 comments

Comments

@congwiny
Copy link

使用例子:

val Builder = "android.app.AlertDialog${'$'}Builder"
        val OnClickListener = "android.content.DialogInterface${'$'}OnClickListener"

        Log.e("Reflect","11111")
        Builder<Context>(this)                     // Like AlertDialog.Builder(context)
                .calls("setTitle")("Hello World")    // Call matched specific named function
                .calls("setPositiveButton")("OK",
                OnClickListener.createInners {
                    // Like object: DialogInterface.OnClickListener
                    /***
                     *  Like:
                     *  override fun onClick(dialog: Any, which: Int){
                     *
                     *  }
                     */
                    override<Any, Int>("onClick") { dialog, which ->

                    }
                })
                .calls("create").calls("show")()     // Like builder.create().show()
        Log.e("Reflect","22222")

2020-05-19 14:25:59.881 11753-11753/com.cc.test E/Reflect: 11111
2020-05-19 14:26:03.056 11753-11764/com.cc.test I/iesupportsampl: Background concurrent copying GC freed 95320(4MB) AllocSpace objects, 2(40KB) LOS objects, 65% free, 3MB/9MB, paused 493us total 126.728ms
2020-05-19 14:26:05.403 11753-11753/com.cc.test E/Reflect: 22222
2020-05-19 14:26:05.407 11753-11753/com.cc.test I/Choreographer: Skipped 331 frames! The application may be doing too much work on its main thread.
通过运行日志发现,执行这段代码产生了掉帧,主线程卡顿的问题。

如果是正常的创建Dialog,耗时很小。

Log.e("Reflect","33333")

        AlertDialog.Builder(this)
                .setTitle("Hello Word")
                .setPositiveButton("OK", DialogInterface.OnClickListener { dialog, which ->

                })
                .create()
                .show()
        Log.e("Reflect","44444")

2020-05-19 14:25:56.320 11753-11753/com.cc.test E/Reflect: 33333
2020-05-19 14:25:56.465 11753-11753/com.cc.test E/Reflect: 44444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant