I am designing an app which is a kind of articles reader & manager and articles available in different languages.
So when user reads a particular article in Russian there is a button to display the same article in English and vice versa.
To do that I start new activity.
What I have now is that if user presses “translate” button of the same article several times there will be heaps of duplicate activities.
What I need to achieve is that when user first “translates” Russian article to English, then presses “translate” button in an English article, the app returns him to existing activity displaying Russian Article and does not start a new Activity. Here is a code which does not do what I need to illustrate my attempts.
intent.putExtra("BookID", strBookID );
intent.putExtra("ChapterNum", mCurrChapterNum );
intent.putExtra("TextNum", mCurrTextNum );
try{
if (Central.LastBookID.equals(""))
{ //remember current article id
Central.LastBookID=strBookID;
Central.LastChapter=mCurrChapterNum;
Central.LastText=mCurrTextNum;
}
else
{
if (Central.LastChapter.equals(mCurrChapterNum) &&
Central.LastText.equals(mCurrTextNum) )
intent.addFlags(Intent. FLAG_ACTIVITY_REORDER_TO_FRONT);
}
startActivity(intent);
Please give me some advice, maybe it would be better to implement it differently?
From what I managed to read, Android does not have any “Activity ID”s so that if I have 2 activities of the same class “A” in stack but with different parameters like (A1 A2), I could tell the system to bring to front activity A1 and make it (A2 A1)
using the above flag instead will finish the prevoius one and starts the new one. so no heap of Activities and no extra logic.