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

后端 未结 7 2257
南方客
南方客 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条回答
  • 2021-02-12 12:54

    Just create an activity object/instance like new YourActivity().

    public static void Redirect(Context context,Activity page) {
    
    ..... //code
    
    context.startActivity(new Intent(context,page.getClass()));
    
    ((Activity) context).finish();
    }
    

    and use this method as

    Redirect(Registration.this, new YourActivity());
    
    0 讨论(0)
提交回复
热议问题