I am developing an android app where i am creating a shortcut from HomeActivity
and from that shortcut i move back to HomeActivity
.
My problem is i want to send some url in shortcut and want to get back that url when user come from shortcut to HomeAtivity
.
Here's code :
HomeActivity
private void addShortcut() {
Intent shortcutIntent = new Intent(getApplicationContext(),HomeActivity.class);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.putExtra("shortcutKey", "www.myapi.com/fromshortcut");
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, AppConstants.shortcutTitle);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.ic_launcher));
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
Toast.makeText(getApplicationContext(), AppConstants.shortcutDone, 40).show();
Shortcut is created successfully.
Now i click on Shortcut and come back to HomeActivity
and getting Intent
but with null pointer exception...
String shortcutUrl = getIntent().getStringExtra("shortcutKey");
if(shortcutUrl.equals("")){
setupWebView("http://stackoverflow.com");
}
else{
Log.e("shortcut was created", "url from shortcut");
setupWebView(shortcutUrl);
}
So what should i do to get that data back.Thanks in advance and ready to vote up for right answer.