Android : launch external activity in the same task

on Thursday, October 30, 2014


How do I regard a task: open the task manager to see.


I have been thinking that it's impossible to start an external activity in the current task since long time ago. But I have found this is INCORRECT!


My app could start a twitter/facebook/sms in the same task (when clicking the task manger button, I could only see my task). But this doesn't apply to browsers. I have tried two browser app chrome and firefox. None of them works like twitter/facebook/sms


The following are the code for open a facebook client and a browser. Any comments would be really appreciated!



public Intent shareViaFacebook(Activity ctx) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
ActivityInfo appInfo = searchForApp(ctx, intent, "facebook");

if (appInfo == null)
return null;

intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(appInfo.packageName, appInfo.name));

intent.putExtra(Intent.EXTRA_TEXT, "message");
return intent;
}


public Intent launchBrowser(Activity ctx, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

ActivityInfo appInfo = searchForApp(ctx, intent, null);
if (appInfo == null)
return null;
intent.setComponent(new ComponentName(appInfo.packageName, appInfo.name));
intent.addCategory(Intent.CATEGORY_LAUNCHER);
return intent;
}

0 comments:

Post a Comment