I solved the issue. The problem was that I was testing on what it does when user unauthorizes the application. And I unauthorized the application from twitter account which I used to create application at dev.twitter.com. Doing this invalidated my accesstoken which was stored in shared preferences and hence in my code when I fetch it from shared preferences and use it, I used to get exception.
The solution is to recreate an accesstoken in application created at dev.twitter.com. And in my code I added this condition :
catch (TwitterException e) {
if (e.getStatusCode() == -1) {
// This is the case when the developer who created the application has revoked the application permission.
// In this case we need to remove stored access token as it is no longer valid.
// Logging in again will fetch newer accesstoken and will solve the problem.
logoutFromTwitter();
loginToTwitter();
}
}