where:
- PACKAGE_NAME is the name of the package.
- CLASS_NAME is the name of the class inside the package.
For example, we have another installed app in package "com.test.AndroidSlave", we can start the activity "com.test.AndroidSlave.AndroidSlaveActivity" inside the package.
![Start a specified app Start a specified app](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-9QCZd5rBzRlCO74XQFQ7KNqKmYGYdtkRxQEHT3UvhyFaLVThu8tBTgSfPce0gxppKidlRIs4A6yUB5X9Wofetywp887RXygAkhM0c1X585CEuGG0noVAith3j6g9ha4XtxVrSUqsngxN/s400/MasterSlave_01.png)
package com.test.AndroidMaster;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AndroidMasterActivity extends Activity {
final static String PACKAGE_NAME = "com.test.AndroidSlave";
final static String CLASS_NAME = "com.test.AndroidSlave.AndroidSlaveActivity";
Button btnStartSlave;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnStartSlave = (Button)findViewById(R.id.startalave);
btnStartSlave.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startSlave();
}});
}
private void startSlave(){
Intent intent = new Intent();
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
startActivity(intent);
}
}
Next post:
- Start a specified app with data passed
- Check if a app is instlled
Thanks for the simple explanation.
ReplyDelete