I am working on a project, what I am doing is I check Read the RSS feeds and save them to my database and display them by selecting the particular story in the list view. When I display the stories I am using Webview, so that I can also open an url if it is present in my story content in webview. Everything works fine.
Now I just want to check if the url if clicked in the story content in the webview is present in the my database, then that database should open In my activity with some HTML tags and WebView. and if the url is not present in my Database then that URL should open in my webview as a link. Still everything is working nice.
The problem is if the url is matched it opens as i require but when I press the backbutton. it crashes, and then come back to the back activity on forced close. whereas if I click a url which is not present in my database it works fine.
Any help would be useful, I am attaching my code here for the same.
content = (WebView) findViewById(R.id.content);
if(getStoryFromDB()!=null){
Uri uri = Story.buildStoryUri(getStoryFromDB());
Intent intent = new Intent("com.india.ui.StoryDetailIntent2.LAUNCH",uri );
Log.d("uri passed:", uri.toString());
startActivity(intent);
//Toast.makeText(this, "Story URL Matched", Toast.LENGTH_LONG).show();
}
else{
content.getSettings().setPluginState(PluginState.ON_DEMAND);
content.getSettings().setJavaScriptEnabled(true);
content.getSettings().setAllowFileAccess(true);
content.setWebChromeClient(new WebChromeClient());
content.setWebViewClient(new WebViewClient());
content.loadUrl(surl);
}
private String getStoryFromDB() {
// TODO Auto-generated method stub
StoryDatabase storiesdb = new StoryDatabase(this);
SQLiteDatabase sqldb = storiesdb.getReadableDatabase();
String sStoryGuid=null;
String selection = StoryColumns.LINK+"=?" ;
String[] selectionArgs = new String[1];
selectionArgs[0] = surl;
try{
Cursor cursor = sqldb.query(StoryDatabase.Tables.STORIES, null, selection, selectionArgs, null, null, null);
startManagingCursor(cursor);
while (cursor.moveToNext()) {
sStoryGuid = cursor.getString(cursor.getColumnIndex(StoryColumns.GUID));
StoriesBean objSb = new StoriesBean();
objSb.setGuid(sStoryGuid);
}
}catch(Exception e){
e.printStackTrace();
}finally{
sqldb.close();
}
return sStoryGuid;
}
I searched for it, think I found the reason, as I am using startManagingCursor(). and now it is deprecated, And I should use contentResolver or loader. but I am not able to put it in code,and I don't have any Idea how to implement it. I searched but couldn't find any way to resolve it.
Any help would be appreciated. Thanks in advance.