Changing mContext when changing Activity

Put your problem here if it does not fit any of the other categories.

Changing mContext when changing Activity

Postby rocksolide » Tue May 27, 2008 12:22 pm

Hi,

I'm facing some problems with mContext. When passing from an Activity to another, the previous mContext remains in the new Activity, instead of the new mContext. This is what I did:

I'm in a View, launched from the first Activity, and this code is in the View. When I "win" (mMode==WIN), I should go on a new Activity, with new Context...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         if (mMode == READY)
  3.  
  4.                                 str = res.getText(R.string.mode_ready);
  5.  
  6.                         else if (mMode == PAUSE)
  7.  
  8.                                 str = res.getText(R.string.mode_pause);
  9.  
  10.                         else if (mMode == LOSE){
  11.  
  12.                                 str = res.getText(R.string.mode_lose);
  13.  
  14.                                 //Intent i = new Intent(Intent.RUN_ACTION, null, mContext, Anim.class);                    
  15.  
  16.                                 //mContext.startActivity(i);
  17.  
  18.                         }else if (mMode == WIN)
  19.  
  20.                                 str = res.getString(R.string.mode_win_prefix)
  21.  
  22.                                 + mWinsInARow + " "
  23.  
  24.                                 + res.getString(R.string.mode_win_suffix);
  25.  
  26.  
  27.  
  28. // Intent to move to the other Activity        
  29.  
  30.         Intent i = new Intent(Intent.RUN_ACTION, null, mContext, <next Activity>.class);                    
  31.  
  32.         mContext.startActivity(i);
  33.  
  34.  
Parsed in 0.044 seconds, using GeSHi 1.0.8.4


The problems with this code, is that Android doesn't even wait for me to "win", in order to move to the new Activity... I will add a Thread, it might be the solution. But the main problem is the Context... How can I replace the old context with the next Activity's View Context?

If you need more Codes to understand, I can provide you the files..
rocksolide
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Apr 30, 2008 11:44 am
Location: Grenoble, France

Top

Postby rocksolide » Tue May 27, 2008 1:31 pm

In fact, the main problem in the project is that I want to move from one Activity to another. Shall I use a ListActivity instead of an Activity?
rocksolide
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Apr 30, 2008 11:44 am
Location: Grenoble, France

Postby Jesmiatka » Tue May 27, 2008 1:44 pm

Hi,

can I ask what your intention is of this action?
Why do you want to use that context?

the not waiting before WIN is because you don't use brackets in the lasts else if (I think you want to change activity when player has won?)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. else if (mMode == WIN){
  2.  
  3.                     str = res.getString(R.string.mode_win_prefix)
  4.  
  5.                     + mWinsInARow + " "
  6.  
  7.                     + res.getString(R.string.mode_win_suffix);
  8.  
  9.  
  10.  
  11. // Intent to move to the other Activity      
  12.  
  13.      Intent i = new Intent(Intent.RUN_ACTION, null, mContext, <next Activity>.class);                    
  14.  
  15.      mContext.startActivity(i);
  16.  
  17. }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


Greetz,
Mike
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 26 guests