ExternalApp opens my android application app. Now in my app, I have a button that returns a value to the external app then closes itself so whatever screen in externalapp opened my app is on top.
while no error is thrown, my application's screen remains on top and I cant see if the value has been sent to the calling external app:
public void sendBackData() {
Intent intent = new Intent();
intent.putExtra("value", "user");
setResult(RESULT_OK, intent);
finish();
}
I have tried this.finish() but it made no difference. Basically, after button click calls sendBackData method, I want the application to pass the value user to the calling external application and hide/close the screen.
My app has a service that runs in the background. It wakes up on intent from the user which is typically generated from another application (such as sharing to my app from the web browser). After the service is done performing a task I want it to open an Activity that displays some info about the task that was completed. When the user is done looking at this info, I want them to be able to hit 'Back' or 'Close' and return to what they were doing previously (not within my application).
I've only managed to get the activity to close leaving my App's main activity front and center on the screen. This only happens if the app is still running. If it's been killed then it correctly returns to the web browser where the user intent was generated from.
How can I make the 'Back' button close the activity and return to the previous app from which this entire workflow was started?
EDIT:
This is the code I am executing from within the android service:
Intent intent = new Intent(this, TestActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
When I tap the back button from the TestActivity it returns me to the main activity of my app, not the previous app I was in when the service started TestActivity.
In second line you are using Intent.FLAG_ACTIVITY_CLEAR_TOP which is clearing your previous activity
There 2 apps: First app can open the second one using:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.my.path");
startActivity(intent);
this works fine.
Second app can call again the first app by using intents with actions. for example:
public void call(String number)
{
Intent myIntent = new Intent(Intent.ACTION_CALL);
myIntent.setData(Uri.parse("tel:" + number);
startActivity(myIntent);
}
And there lies a problem which I'll get to shortly.
I'm handling the received intent in the first app in the onCreate method. The first app is simply a single activity with many fragments which are switched with a fragment transaction. When receiving the intent from the second app, I'm making a transaction to a specific fragment according to the intent.
The problem is that when the first app is not in the background (meaning its close), my handling of the intent works fine. However, if the user opened the second app from the first one and the first one is still in the background, then when a user calls the intent in the second app, the first app is getting back to the foreground but to the same fragment the user was when he launched the second app, while I was expecting to show the new fragment which is based on the user's request in the intent sent from the second app.
Why is this happening and how can I fix it?
You could handle this by overriding the OnNewIntent method handling the intent and bringing to top the required fragment.
I am launching skype with the below code from a button click.
Uri skypeUri = Uri.parse(uri.toString());
Intent myIntent = new Intent("android.intent.action.CALL_PRIVILEGED", skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appContext.startActivity(myIntent);
It gets launched as a seperate activity and my app goes in background. When call is done, and i click on my app from background running apps, it starts from first screen however the call was placed from third screen. Any idea where I am wrong in implementation.
I want my app to go to background as soon as call button is clicked. When i am done with skype call and starts it again from background running apps it should not start from first screen. It should start from that 3rd screen only where i left it.
Thanks
I have Twitter OAuth working in my application using an intent-filter in my manifest. How I have implemented it, once the user clicks a button to post via Twitter I start a new Activity (lets just called it TwitterLoginActivity), that new TwitterLoginActivity creates a new Intent with the authUrl like this:
Intent oauthIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
This opens a browser, I authorize my app, and it returns in the onResume() function of TwitterLoginActivity. At this point I post to twitter just fine and do a finish() on this activity.
All this works like a champ, but in calling this finish() it returns to the Twitter.com webpage I just authorized from. I'm not great at understanding how the activity stack works, but is there anyway to remove all of the WebViews of Twitter.com that I saw and on that finish() it just returns back to the original point in my application where the user had clicked the post button?
I don't know if you resolved your issue, but yesterday I had the same problem and I resolved it this way:
1) In the intent to lauch the WebBrowser to sign in on Twitter, add the next flags:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
2) In the Manifest, where you declare the TwitterLoginActivity that launches the intent, add the property:
android:launchMode="singleTask"
3) When the login with Twitter is completed, WebBrowser finishes and goes back to TwitterLoginActivity but onCreate isn't called because of singleTask launch mode, onNewIntent is called instead. To save the token and token secret, you have to move the code from onResume to OnNewIntent.
Now, if you press the back button or finish TwitterLoginActivity, it goes to the previous activity and the WebBrowser never shows up again.
I hope this helps!
This works for me: render the oauth web page in a WebView you control rather than launching out to the browser app.
The oauth web page, when it calls its callback, will actually be replacing itself in the webview, where your WebViewClient can catch that expected URL, process the results, and finish() the webview (removing it from the activity stack).
In other words, the WebView will be under your direct control, rather than being the browser.
This sounds like a perfect time to use Activity.startActivityForResult() instead of Activity.startActivity(). You're original activity just needs your TwitterLoginActivity to login the user, so once done, it should return back to your original activity.
Implement onActivityResult() to handle the response from TwitterLoginActivity.
Read about it here