Android how to pass an Activity.class as an argument for a function

后端 未结 7 2260
南方客
南方客 2021-02-12 12:22

I recently moved to Android from python and am stuck here.

This is my class declaration to create a common function for an Alert Dialog which accepts necessary parameter

7条回答
  •  -上瘾入骨i
    2021-02-12 12:40

    This works for me:

    private void switchActivity(Class cls){
        Intent intent = new Intent(HomeActivity.this, cls);
        startActivity(intent);
    }
    

    Call the function like this: switchActivity(DestinationActivity.class)

提交回复
热议问题