0

I try with this ways but did not get correct way to do this.I am using this code to open another app.

Now i want to know when ever i close or open my second app then i want to get some result of closing second app or opening second app in to my first app.Can it is possible or not if it is possible to get any responce of opening second app or closing second app.

Intent intentt = new Intent(Intent.ACTION_MAIN);
intentt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentt.setComponent(new ComponentName("com.example.abc","com.example.abc.MainActivity"));
startActivity(intentt);

This code open my second app after press back button my second app will close at the time of close and opening second app i want to get some result at the time of second app opening or closing some result,i also follow these links also.

I also follow this link to explore or find solution

how i can do this...Thanks in Advance.

with this code my second app is open but after closing second app how do i find or handle callback of second app.

Maveňツ
  • 1
  • 12
  • 50
  • 89
Amitsharma
  • 1,577
  • 1
  • 17
  • 29
  • Is the second app under your control? Can you change code in that app? – David Wasser Aug 30 '16 at 20:17
  • @David Wasser no my second app is not in my control is there any way to resolve it – Amitsharma Aug 31 '16 at 04:38
  • If the second app is supposed to return something to your app, you need to know how the second app is doing this (the documentation for the second app should explain how it returns results). If you don't know, then there isn't anything you can do? What is the second app? – David Wasser Aug 31 '16 at 09:36
  • i am not handling my second app i have rights of first app so i cant get any return type any thing from second app. – Amitsharma Aug 31 '16 at 09:48
  • What does _"i am not handling my second app i have rights of first app so i cant get any return type any thing from second app"_ even mean? What kind of callback to you expect from the second app? Please provide more details in your post! – David Wasser Aug 31 '16 at 10:17
  • First of all i Run my app then i have write the code to open another app from frist app when ever my second app open then i want to know that my second app open and after that when second app closed then i want to know my second app is closed i have not any rights to handle second app or code ... that sit – Amitsharma Aug 31 '16 at 12:40

3 Answers3

0

You Should use startActivityForResult() method to open or close second app because here we pass the intent and request code as parameter which helps to get response in onActivityResult() method.

PRIYA PARASHAR
  • 777
  • 4
  • 15
0

From your FirstApp call the SecondApp using startActivityForResult() method

For example:

  intent = new Intent(Intent.ACTION_VIEW);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setData(Uri.parse("market://details?id=" + "com.package.name"));

    startActivityForResult(intent, 2404);

When user press back button it will notify in onActivityResult method of FirstApp.

Pass data with Intent and then finish that activity in Second App.Put whatever your data is with putExtra. Write this in Second App:

byte[] byteArray = stream.toByteArray();
            Intent intent = new Intent();
            intent.putExtra("tile", 1);
            intent.putExtra("image", byteArray);
            setResult(2404,intent);
            finish();

Write following code for the in FirstApp. To access the result passed from Second App

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 2404) {
        if (data != null)// To check for NullPointerException { 
            byte[] byteArray = data.getByteArrayExtra("image");
            Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
          //Your code 
        }
    }
}

For more Detail check this link:

  1. StartActivity 2.StartActivityForResult 3.OnActivityResult
Dipali Shah
  • 3,742
  • 32
  • 47
0

Try With this code for opening one application to another application

Intent launchIntent = 
getPackageManager().getLaunchIntentForPackage("com.package.address");

if (launchIntent != null) { 
startActivity(launchIntent);//null pointer check in case package name 
 was not found
}