TabGroupActivity + Prevent reload of an activity onBackPressed - android

This is the code of my TabGroupActivity. Here On any of the particular tab Tab B-> then It will launch Its child activity Class C -> then on click of any button It will again calls the child activty Class D
Now from class D whenever I pressed back button, then It will again reload the child activity class C. From class C, when I press the back button, again It will reload the child activity.
Please help me into this.. I dont want the previous activity to reload.
public class TabGroupActivity extends ActivityGroup {
private ArrayList<String> mIdList;
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
if (mIdList == null) mIdList = new ArrayList<String>();
}
/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {#link LocalActivityManager#destroyActivity} on the child activity
* and starts the previous activity.
* If the last child activity just called finish(),this activity (the parent),
* calls finish to finish the entire group.
*/
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
Log.i("Stack,finishFromChild", ""+mIdList);
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
lastIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
/**
* Starts an Activity as a child Activity to this.
* #param Id Unique identifier of the activity to be started.
* #param intent The Intent describing the activity to be started.
* #throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) {
Window window = getLocalActivityManager().startActivity(Id,intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
/**
* The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
* from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
*/
/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK.
* Simply override and add this method.
*/
#Override
public void onBackPressed () {
int length = mIdList.size();
if ( length > 1) {
Log.i("Stack,onback", ""+mIdList);
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
Log.i("Activity in current",""+current);
current.finish();
}
else
{
if(length==1)
{
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
Log.i("Activity in current",""+current);
current.finish();
}
}
}

Related

OnResume() is not called in TabHost in Android?

I am working with Tabs in my application. Worked on the TabHost Class to make it customize.
When I have PARENT --> CHILD activity, in this case on back press, onResume of Parent Activity is not called in my application.
I am using the below code:
public class TabGroupActivity extends ActivityGroup {
private ArrayList<String> mIdList;
private HashMap<String, Window> mWindowStorage = new HashMap<String, Window>();//UPDATED
private boolean _isFromResume;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIdList == null) mIdList = new ArrayList<String>();
}
/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {#link LocalActivityManager#destroyActivity} on the child activity
* and starts the previous activity.
* If the last child activity just called finish(),this activity (the parent),
* calls finish to finish the entire group.
*/
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
String actName = mIdList.get(index);
manager.destroyActivity(actName, true);
mWindowStorage.remove(actName);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Window newWindow = null;
if(mWindowStorage.containsKey(lastId)){
newWindow = mWindowStorage.get(lastId);
}else{
Intent lastIntent = manager.getActivity(lastId).getIntent();
newWindow = manager.startActivity(lastId, lastIntent);
}
setContentView(newWindow.getDecorView());
}
/**
* Starts an Activity as a child Activity to this.
* #param Id Unique identifier of the activity to be started.
* #param intent The Intent describing the activity to be started.
* #throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) {
Window window = null;
if(mWindowStorage.containsKey(Id)){
window = mWindowStorage.get(Id);
if(_isFromResume){
setFromResume(false);
mIdList.clear();
mIdList.add(Id);
mWindowStorage.clear();
mWindowStorage.put(Id, window);
}
}else{
window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
mWindowStorage.put(Id, window);
}
}
setContentView(window.getDecorView());
}
/**
* The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
* from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
*/
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK
* so that all systems call onBackPressed().
*/
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
return true;
}
return super.onKeyUp(keyCode, event);
}
/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK.
* Simply override and add this method.
*/
#Override
public void onBackPressed () {
int length = mIdList.size();
if ( length > 0) {
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
current.finish();
}
}
public void setFromResume(boolean isFromResume) {
_isFromResume = isFromResume;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Activity activity = getLocalActivityManager().getCurrentActivity();
RegisterDeRegisterResponse register = RegisterDeRegisterResponse
.getInstance();
register.notifyRegisteredUser(requestCode, resultCode, data);
register.deRegisterForServerResponse((IResultResponse) activity);
}
public void switchTab(int i) {
WeddingTabActivity parentActivity = (WeddingTabActivity) getParent();
parentActivity.switchTab(i);
}
}
Also worked with default startChildActivity(String Id, Intent intent) and finishFromChild(Activity child) methods but in that case every Activity is relaunched on BackPress.
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
public void startChildActivity(String Id, Intent intent) {
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
In tab host I have done a whole project and then same problem I have the onresume does not get called.. and the activity group is now deprecated and you will be not able to call onresume check this may be it will help.. best of luck

TabActivity,Activities containing fragments

I have 5 tabs.Each tab contain multiple activities and each activity contain multiple fragments.
For eg:Navigation needed is In tab1 - Activity1 - Fragment1_Activity1 - Fragment2_Activity1 - Activity2 - Fragmnet1_Activity2
I used ActivityGroup to show Activity2 inside the Tabs.
ActivityGroupClass:
public class CouponsActivityGroup extends ActivityGroup {
private Stack<String> stack;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (stack == null) stack = new Stack<String>();
//start default activity
push("FirstStackActivity", new Intent(this, CouponsContianer.class));
}
#Override
public void finishFromChild(Activity child) {
pop();
}
#Override
public void onBackPressed() {
pop();
}
public void push(String id, Intent intent) {
Window window = getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
stack.push(id);
setContentView(window.getDecorView());
}
}
public void pop() {
if (stack.size() == 1) finish();
LocalActivityManager manager = getLocalActivityManager();
manager.destroyActivity(stack.pop(), true);
if (stack.size() > 0) {
Intent lastIntent = manager.getActivity(stack.peek()).getIntent();
Window newWindow = manager.startActivity(stack.peek(), lastIntent);
setContentView(newWindow.getDecorView());
}
}
}
From Fragment2_Activity1 am calling Activity2 using the following code:
Intent intent = new Intent();
intent.setClass(getParent(), RelatedItemListActivity .class);
CouponsActivityGroup activityStack = (CouponsActivityGroup) getParent();
activityStack.push("SecondStackActivity", intent);
Issue am facing now is
I want to set a transition animation for Activity2
On pressing back from Activity2 - last Fragment state in Activity1(Fragment2_Activity1) need to be maintained.
How to achieve this?
Fragments are some kind of replacement of old ActivityGroups and shouldn't be used together. Try to implement your application using only one activity and as many fragments as you need.
Answering your questions:
FragmentManager helps you to set an animation. See FragmentTransaction.setCustomAnimations .
Use addToBackStack method to support back button proper way.

backpress is not being called inside activity group android

In my android application i am using activity group inside tabs,am maintaining the list of previous screens as well.The issue is,if we press back immediately after the screen gets loaded ,the Backpress method is not called and the app gets exited,whereas if i do the same after a delay say 30 secs in the screen it works as expected.Could not resolve the issue at all.Have debugged the code and have noticed that the new screen is added to the stacklist but the backpress method itself is not called.Tried implementing backpress in the activity and also in tabgroup class but no use.Please let me know where i am going wrong.The code that i use to add a activity is
Intent intent = new Intent(context, TrialActivity.class);
intent.putExtra("feedId", moreitems.get(arg2).getItem_id());
intent.putExtra("heading", moreitems.get(arg2).getItem_name());
TabGroupActivity parentActivity = (TabGroupActivity) ((Activity) context)
.getParent();
parentActivity.startChildActivity(moreitems.get(arg2).getItem_name()
+ Calendar.getInstance().getTimeInMillis(), intent);
MyTabgroup class is
#SuppressWarnings("deprecation")
public class TabGroupActivity extends ActivityGroup {
private ArrayList<String> mIdList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIdList == null)
mIdList = new ArrayList<String>();
}
#Override
protected void onPause()
{
super.onPause();
}
#Override
protected void onResume() {
// to start the first activity every time on reload( on focus of tab).
// remove the search activity if it is in the stack
if (mIdList != null && mIdList.size() > 0) {
int index = -1;
for (int i = 0; i < mIdList.size(); i++) {
String firstId = mIdList.get(i);
if (firstId != null
&& "search".equalsIgnoreCase(firstId.substring(0,
firstId.length() - 1))) {
index = i;
}
}
if (index != -1) {
LocalActivityManager manager = getLocalActivityManager();
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index);
index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
}
super.onResume();
}
/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {#link LocalActivityManager#destroyActivity} on
* the child activity and starts the previous activity. If the last child
* activity just called finish(),this activity (the parent), calls finish to
* finish the entire group.
*/
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size() - 1;
if (index < 1) {
Alerts.exit("Confirm",
"Do you really wish to exit from iDream Media?", this);
return;
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index);
index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
/**
* Starts an Activity as a child Activity to this.
*
* #param Id
* Unique identifier of the activity to be started.
* #param intent
* The Intent describing the activity to be started.
* #throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) {
Window window = getLocalActivityManager().startActivity(Id,
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
/**
* The primary purpose is to prevent systems before
* android.os.Build.VERSION_CODES.ECLAIR from calling their default
* KeyEvent.KEYCODE_BACK during onKeyDown.
*/
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// onBackPressed();
// preventing default implementation previous to
// android.os.Build.VERSION_CODES.ECLAIR
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK so that
* all systems call onBackPressed().
*/
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
return true;
}
return super.onKeyUp(keyCode, event);
}
/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK. Simply override and
* add this method.
*/
#Override
public void onBackPressed() {
int length = mIdList.size();
if (length > 1) {
Activity current = getLocalActivityManager().getActivity(
mIdList.get(length - 1));
current.finishFromChild(current);
}
}
}
Please let me know where i am going wrong.
I finally found out that the issue was beacause of the ads display on top of tab.Referred to the below link and it got resolved.
Back button behavior with tabs and ActivityGroup

Local Activity manager issue in android

I use Local activity manager in my tab group activity class for switch over b/w various activity in Tab, for example from my main Tab1 i switch over b/w following activities Act1->Act2->Act3.
Where in act2 i call web service based on data from tab1, then i move to Act 3. But when i click back button Act2 onCreate will invoke again.
I found that there is issue in android local activity manager and implemented correponding fix code in destroy method.
Here is overall tabgroup activity code..
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Map;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
/**
* The purpose of this Activity is to manage the activities in a tab.
* Note: Child Activities can handle Key Presses before they are seen here.
* #author Eric Harlow
*/
public class TabGroupActivity extends ActivityGroup {
private ArrayList<String> mIdList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIdList == null) mIdList = new ArrayList<String>();
}
/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {#link LocalActivityManager#destroyActivity} on the child activity
* and starts the previous activity.
* If the last child activity just called finish(),this activity (the parent),
* calls finish to finish the entire group.
*/
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
System.out.println("Destroy called");
boolean rt=destroy(mIdList.get(index),manager);
System.out.println("Destroy called"+rt);
// manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
/**
* Starts an Activity as a child Activity to this.
* #param Id Unique identifier of the activity to be started.
* #param intent The Intent describing the activity to be started.
* #throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) {
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
/**
* The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
* from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
*/
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK
* so that all systems call onBackPressed().
*/
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
return true;
}
return super.onKeyUp(keyCode, event);
}
/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK.
* Simply override and add this method.
*/
public void onBackPressed () {
int length = mIdList.size();
if ( length > 1) {
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
System.out.println("Activity Being close"+current.getLocalClassName());
current.finish();
}
}
public boolean destroy(String id,LocalActivityManager activityManager) {
if(activityManager != null){
activityManager.destroyActivity(id, false);
// http://code.google.com/p/android/issues/detail?id=12359
// http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/app/LocalActivityManager.java
try {
final Field mActivitiesField = LocalActivityManager.class.getDeclaredField("mActivities");
if(mActivitiesField != null){
mActivitiesField.setAccessible(true);
#SuppressWarnings("unchecked")
final Map<String, Object> mActivities = (Map<String, Object>)mActivitiesField.get(activityManager);
if(mActivities != null){
mActivities.remove(id);
}
final Field mActivityArrayField = LocalActivityManager.class.getDeclaredField("mActivityArray");
if(mActivityArrayField != null){
mActivityArrayField.setAccessible(true);
#SuppressWarnings("unchecked")
final ArrayList<Object> mActivityArray = (ArrayList<Object>)mActivityArrayField.get(activityManager);
if(mActivityArray != null){
for(Object record : mActivityArray){
final Field idField = record.getClass().getDeclaredField("id");
if(idField != null){
idField.setAccessible(true);
final String _id = (String)idField.get(record);
if(id.equals(_id)){
mActivityArray.remove(record);
break;
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
return false;
}
}
i don`t know how to prevent restart activity.If any one knows the solutions help me out.
Thanks.
I resolve the issue in following way but i don`t know whether it cause any problem,
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
System.out.println("Destroy called");
destroy(mIdList.get(index),manager);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
setContentView(newWindow.getDecorView());
}
simply restore the activity using intent flag, Intent.FLAG_ACTIVITY_SINGLE_TOP which resume our activity by bringing it to front without restarting it.

TabGroupActivity - startChildActivity - not working

I have been using TabActivity and I want the tab to display on every child activity. I have flow like this MainActivity(TabActivity) -> TabGroupActivity1(TabGroupActivity) -> Activity1 -> Activity2
Now i want to redirect on Activity2 only if the flag is true. so that my code for that is something like bellow.
TabGroupActivity
public class TabGroupActivity extends ActivityGroup {
private ArrayList<String> mIdList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIdList == null) mIdList = new ArrayList<String>();
}
/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {#link LocalActivityManager#destroyActivity} on the child activity
* and starts the previous activity.
* If the last child activity just called finish(),this activity (the parent),
* calls finish to finish the entire group.
*/
#Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
/**
* Starts an Activity as a child Activity to this.
* #param Id Unique identifier of the activity to be started.
* #param intent The Intent describing the activity to be started.
* #throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) {
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
/**
* The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
* from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
*/
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK
* so that all systems call onBackPressed().
*/
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
return true;
}
return super.onKeyUp(keyCode, event);
}
/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK.
* Simply override and add this method.
*/
#Override
public void onBackPressed () {
int length = mIdList.size();
if ( length > 1) {
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
current.finish();
}
}
}
now code for TabGroupActvity1
public class TabGroupActyvity1 extends TabGroupActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startChildActivity("OptionsActivity", new Intent(this,Activity1.class));
}
}
now in Activity1
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(flag){
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
Intent previewMessage = new Intent(parentActivity, Activity2.class);
parentActivity.startChildActivity("Activity2", previewMessage);
}else{
setContentView(R.layout.row);
//...
}
}
this is not working,
the same code the one in bellow works in some click event but not working in my case
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
Intent previewMessage = new Intent(parentActivity, Activity2.class);
parentActivity.startChildActivity("Activity2", previewMessage);
please give some suggestion how to do this.
have I explain the problem well... do I need to add some more details?
Okay, I found other alternative.
Instead of...
checking flag in the child activity and redirecting on different page.
I am checking the flag in the parnt activity Like this
if (getLNApplication().isLogin()) {
startChildActivity("Report", new Intent(this, ReportActivity.class));
}else{
startChildActivity("LogIn", new Intent(this, LoginActivity.class));
}
and from LoginActivity on Successful login i am Starting ReportActivity like bellow
parentActivity.startChildActivity("EditActivity", new Intent(getParent(), ReportActivity.class));
and I also handle the back press as of I don't want user to go back on login page again. I handle the back key in TabGroupActivity
like this
#Override
public void onBackPressed() {
int length = mIdList.size();
if (length > 1) {
Activity current = getLocalActivityManager().getActivity(
mIdList.get(length - 1));
// Added code to disable back press only for the ReportActivity
if(current instanceof ReportActivity){
Log.i("TabGroup", "I am instance of ReportActivity" );
return;
}
current.finish();
}
}

Categories

Resources