Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

starting activities without .class

I have searched for how to start and Activity from another Activity and I keep finding

Intent intent = new Intent(this, ExampleClass.class); startActivity(intent);

But I want to start from an instantiated activity. I have a container with many activities and when the user selects from my UI I wish to show a particular one.

So, for example.

class MyExample extends Activity {

MyExample mx = new MyExample();

So how do I now start this Activity.

What I would like is

Intent intent = new Intent(this, mx);
startActivity(intent);

Any help greatly appreciated from a reasonably experienced Java developer but new to Android.

like image 798
user2244131 Avatar asked Sep 01 '26 08:09

user2244131


1 Answers

This is possible, though I do not understand yet why you want to do this.

Make sure the Activity you want to startis well declared in your manifest :

<activity android:name=".com.example.MyExample" ... />

Then you can call in you current Activity :

Intent myIntent = new Intent();
myIntent.setComponent(new ComponentName("com.example", "com.example.MyExample")); 
startActivity(myIntent);
like image 116
Halim Qarroum Avatar answered Sep 03 '26 23:09

Halim Qarroum