How do I close an external app like Instagram launched from my app and return to the Triggering App?

How do I close an external app like Instagram launched from my app and return to the Triggering App?



I have an Android App which uses Intent to launch Instagram, to my page. Once the user is done with Instagram and closes it with the back arrow, I need instagram to close and return the user back to my Android App which triggered the activity. my Intent works and opens instagram but with the back button it stays in instagram. Find below my code triggering instgram


public void LaunchInstgram(View view)

Intent openInstagram = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
openInstagram.setData( Uri.parse( "https://www.instagram.com/_u/eatoutlagos") );
try
startActivity(openInstagram);
catch (ActivityNotFoundException e)
Toast.makeText(this, "Sorry, Instagram Not Installed", Toast.LENGTH_LONG).show();







Possible duplicate of stackoverflow.com/questions/23579725/…

– Anurag Bannur
Sep 15 '18 at 9:47




1 Answer
1



I think you are calling finish() method in you MainActivity before starting Instagram App via Intents


finish()


MainActivity


Instagram


Intents



The scenario which you have described will occur in following two ways:



EITHER



You have set android:noHistory = "true" for MainActivity inside AndroidManifest.xml which causes MainActivity to finish automatically on pressing the back key.


android:noHistory = "true"


MainActivity


AndroidManifest.xml


MainActivity



OR



Before switching to your LaunchInstragram, you have called finish() in your MainActivity, which kills it. When you press back button,since no other activity is present in stack to pop, it stays there...


LaunchInstragram


finish()



Also you could try ChatHeads on you App by clicking the following link



EDIT



try the following code :


Uri uri = Uri.parse("https://www.instagram.com/_u/eatoutlagos");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);

likeIng.setPackage("com.instagram.android");

try
startActivity(likeIng);
catch (ActivityNotFoundException e)
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.instagram.com/_u/eatoutlagos")));






thanks Amit, let me try out the options

– Noruwa
Sep 15 '18 at 18:43






hi Amit, I dont seem to be able to get the first two options working. At which stage in my mainActivity do i put the finish() method? If i put it in the onCreate method it doesnt start the activity at all when i click the button to start. I put it in the method that launches the instagram intent and there is not change, instagram still doesnt close back to my app

– Noruwa
Sep 15 '18 at 19:26






public void LaunchInstgram(View view){ finish(); Intent openInstagram = getPackageManager().getLaunchIntentForPackage("com.instagram.android"); openInstagram.setData( Uri.parse( "instagram.com/_u/eatoutlagos") ); try startActivity(openInstagram); catch (ActivityNotFoundException e) { Toast.makeText(this, "Sorry, Instagram Not Installed", Toast.LENGTH_LONG).show(); //startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("instagram.com/eatoutlagos"

– Noruwa
Sep 15 '18 at 19:27






in the second case I have put the command in the manifest file within the activity that launches the Intagram app as below <activity android:name=".ContactUs" android:noHistory = "true"/>

– Noruwa
Sep 15 '18 at 19:31






but it has no effect. I am not writing the code correctly? please have a look at what i have shared

– Noruwa
Sep 15 '18 at 19:32



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế