sundeep
sundeep

Reputation: 601

Calling Main activity of an application from another application

I want to use zirco browser in my application hence i have taken the code and started to embed it into my application. so there is this MainActivity in zirco which is the starting point of application i.e the main activity. Zirco code works fine on alone but since i have to call this MainActivity of zirco from my application i have changed the code as follows.

added extra activity. Made this as main activity of the application. calling the MainActivity of Zirco code from the newly created activity.

newly created activity has the following code

    public  void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("org.zirco", "org.zirco.ui.activities.MainActivity"));
    startActivity(intent);
}

So expected behavior is that the browser should run normally as i just created an extra activity, made it main activity and calling the original MainActivity from it. But the browser just opens and then relaunches the application on performing any operation (search, click links) on it.

How to correct this. Is there any other way to invoke a MainActivity of an application and make it run.

Zirco code is available here http://code.google.com/p/zirco-browser/

Upvotes: 0

Views: 239

Answers (2)

Arvind Kanjariya
Arvind Kanjariya

Reputation: 2097

For example your

packagename = com.abc.xyz

Activityname = MainActivity

than follow below code.

final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);

final ComponentName cn = new ComponentName("com.abc.xyz", "com.abc.xyz.MainActivity");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);

Upvotes: 1

Snicolas
Snicolas

Reputation: 38168

Are you sure embedding a browser if the answer to your problem ?

It is very non-standard and goes again the philosophy of Android intents. Usually you use an intent to open an external browser :

Sending an Intent to browser to open specific URL

Upvotes: 0

Related Questions