I have share option in navigation drawer of my app. On click, its working fine to go respective intent i.e. "share intent". Issue is on pressing back button from whatsapp , my app hangs showing a black screen. Pressing back again does nothing and app has to be killed eventually.I am using coordinator layout. Below are the code snippets:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
sideMenu = (ListView) findViewById(R.id.left_drawer);
mSideMenuListAdapter = new SideMenuListAdapter(this, mDrawerLayout);
sideMenu.setAdapter(mSideMenuListAdapter);
Adapter Code:
holder.share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDrawerLayout.closeDrawer(GravityCompat.START);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT, "XXX");
share.putExtra(Intent.EXTRA_TEXT, "****"));
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(Intent.createChooser(share, "Share link!"));
}
});
Tried different options by using different Intent.Flag but nothing seem to be working. Please advise.
Edit: As asked below is OnCreate method. Have just the starting code as the whole method is quite big initializing lots of stuff.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen_new);
I have have just put the usual methods:
@Override
public void startActivityForResult(Intent intent, int requestCode) {
super.startActivityForResult(intent, requestCode);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onRestart() {
super.onRestart();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}