Issue
I have developed an application that somewhere has an image button.
ImageButton buttoncalllog = (ImageButton)findViewById(R.id.imageButton2);
buttoncalllog.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
startActivity(showCallLog);
finish();
}
});
This button, when its clicked it's open the contact list. The problem is that i cant return to my application! When i press the return button to my device, nothing happens... If i kill my application and open it again the first screen is again the contact list! I have to restart the device or reinstall the application! Any help?
EDIT :
I removed the call to finish()
, but still it's not going back when I press return. My updated code :
ImageButton buttoncalllog = (ImageButton)findViewById(R.id.imageButton2);
buttoncalllog.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
startActivity(showCallLog);
}
});
Solution
Don't call finish()
on your Activity after launching the Intent
.
finish()
is used to kill an Activity and should be called only when you want to finish your Activity. Since you are killing your application after launching the Intent, there is nothing that the app can return to when you press the return button.
ImageButton buttoncalllog = (ImageButton)findViewById(R.id.imageButton2);
buttoncalllog.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(CallLog.Calls.CONTENT_TYPE);
startActivity(showCallLog);
}
});
Answered By - Swayam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.