如何将另一个活动的名称作为参数传递给另一个活动中的方法

时间:2015-01-09 12:20:47

标签: android class android-activity type-conversion

所以我想在这里使用ActivityOptionsCompat

    ActivityOptionsCompat options = 
        ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeViewer.class,
        v,   // The view which starts the transition
        transitionName    // The transitionName of the view we’re transitioning to
        );

第一个参数应该是一个Activity对象,我试图通过相关的类文件提供,但是我得到以下类型转换错误 -

Error:(194, 54) error: no suitable method found for makeSceneTransitionAnimation(Class<NoticeViewer>,View,String)
method ActivityOptionsCompat.makeSceneTransitionAnimation(Activity,View,String) is not applicable
(actual argument Class<NoticeViewer> cannot be converted to Activity by method invocation conversion)
method ActivityOptionsCompat.makeSceneTransitionAnimation(Activity,Pair<View,String>...) is not applicable
(actual argument Class<NoticeViewer> cannot be converted to Activity by method invocation conversion)

我错过了一些非常简单的东西,但它是什么?

1 个答案:

答案 0 :(得分:2)

使用NoticeViewer.this代替NoticeViewer.class将当前活动上下文作为第一个参数传递:

ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeBoard.this,...)