Joel
Joel

Reputation: 3454

Dynamically create an activity

I want to create an activity dynamically. Something like:

Activity a = new Activity();

Is it possible ? Do I need a special permission ? Or is it simply not possible ?

The error I get: I don't get any exception but the program stops when I try to use this instruction.

Upvotes: 22

Views: 11055

Answers (4)

Jaber Shabeek
Jaber Shabeek

Reputation: 186

You can't create Activities at runtime so what you can do is create Layouts at runtime and change the Layout according to the event...

Here you are going to use Layout change instead of starting a new Activity.

Upvotes: 5

RajSharma
RajSharma

Reputation: 1971

Instead of multiple activities you can Fragments. You can use the same Layouts with Fragments and you can instantiate them dynamically and remove. In this way you can create a stack based application.

Upvotes: 1

ferostar
ferostar

Reputation: 7082

You can't instantiate an Activity if it's not in the Manifest, so you can't create one dynamically.

Upvotes: 22

kharles
kharles

Reputation: 326

are you trying to start an activity?

use context.startActivity(intent); where the intent defines what activity you want to start.

Upvotes: -2

Related Questions