user3291869
user3291869

Reputation: 33

Android - How to switch from one application to another application?

Hello I am new in android , I am making an demo application in which I want to send my data from one application to another application.,i have studied about intents for this,but that is used between activities,i have also read about implicit and explicit intents,but I am confuse , How i implement this functionality in android,please help me

     public class MainActivity extends Activity implements OnClickListener {
    private Button _btn_one;
    private Button _btn_two;
    private Button _btn_trd;
    private Button _list_btn;
    private Button _spn_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        _btn_one=(Button)findViewById(R.id.btn_one );
        _btn_one.setOnClickListener(this);

        _btn_two=(Button)findViewById(R.id.btn_two);
        _btn_two.setOnClickListener(this);

        _btn_trd=(Button)findViewById(R.id.btn_trd);
        _btn_trd.setOnClickListener(this);

        _list_btn=(Button)findViewById(R.id.list_btn);
        _list_btn.setOnClickListener(this);

        _spn_btn=(Button)findViewById(R.id.spinner_btn);
        _spn_btn.setOnClickListener(this);
    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent;
        switch(v.getId()){
        case R.id.btn_one:
        intent=new Intent(this,Second.class);
        startActivity(intent);
        break;
        case R.id.btn_two:
            intent=new Intent(this,Third.class);
            startActivity(intent);
            break;
        case R.id.btn_trd:
            intent=new Intent(this,Fourth.class);
            startActivity(intent);
            break;
        case R.id.list_btn:
            intent=new Intent(this,DemoList.class);
            startActivity(intent);
            break;
        case R.id.spinner_btn:
            intent=new Intent(this,SpinnerDemo.class);
            startActivity(intent);
            break;


        }
    }

}

Here I have used intent for switching from one activity to another,now how can I move from one application to another application.

Upvotes: 2

Views: 403

Answers (1)

Mohammad Rababah
Mohammad Rababah

Reputation: 1726

Intent i;
PackageManager manager = getPackageManager();
try {
    i = manager.getLaunchIntentForPackage("app package name");
    if (i == null)
        throw new PackageManager.NameNotFoundException();
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);
} catch (PackageManager.NameNotFoundException e) {

}

Upvotes: 1

Related Questions