0

In my android library, I gave the user an edittext to enter the name of an activity , and I should move to it, In other words I dont know all the activities of the android app

String name_activity=Activityedit.getText();
Intent in=new Intent(Dform.this, ? );

What I should do to move the app to the activity with " name_activity" Thank's

Solution :

String intent_redirect=getPackageName()+"."+Activityedit.getText();
                Class<?> c = null;
                  try {
                    c = Class.forName(intent_redirect);
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Intent in =new Intent(DialForm.this,c);
                startActivity(in);
Ghitay
  • 3
  • 5

3 Answers3

1

try that:

Class cls=Activityedit.class;
Intent in=new Intent(Dform.this, cls );
startActivity(in);
Engr Waseem Arain
  • 1,163
  • 1
  • 17
  • 36
1

Am I getting this right? You want to create an activity during runtime? This is impossible afaik. And why would you want to do this?

PKlumpp
  • 4,913
  • 8
  • 36
  • 64
0

This is NOT possible, you Cannot cast from String to Class.

JohnEye
  • 6,436
  • 4
  • 41
  • 67
Devganiya Hitesh
  • 1,207
  • 2
  • 17
  • 31