Starting activity from a normal class

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

Starting activity from a normal class

Postby kajensmann » Tue Apr 21, 2009 4:18 pm

Hi,

does anyone know, if it's possible to start an activity within a normal class? What i want to do is, that an activity creates an instance of this class and then calls a function, which initiates a new activity. The own context of the calling activity should not be passed to the function.
kajensmann
Freshman
Freshman
 
Posts: 4
Joined: Wed Apr 15, 2009 12:24 pm

Top

Postby padde » Tue Apr 21, 2009 5:15 pm

I doubt its possible without passing the context or a handler etc.

Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby prajkti.khadse » Wed Apr 22, 2009 4:28 am

ou can achieve this by having object of calling activity as a static memeber of itself.
here's the sample code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyCallingActivity extends Activity{
  2.  
  3.  
  4.  
  5.         static MyCallingActivity mObjAct;
  6.  
  7.  
  8.  
  9.         void onCreate(Bundle savedInstanceState)
  10.  
  11.         {
  12.  
  13.                 mObjAct = this;
  14.  
  15.                
  16.  
  17.                 MyNormalClass obj = new MyNormalClass();
  18.  
  19.                 obj.someMethod();
  20.  
  21.        
  22.  
  23.         }
  24.  
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. public class MyNormalClass
  32.  
  33. {
  34.  
  35.  
  36.  
  37.         void someMethod()
  38.  
  39.         {
  40.  
  41.                 Intent i = new Intent(MyCallingActivity.mObjAct,NewActivity.class);
  42.  
  43.                 MyCallingActivity.mObjAct.startActivity(i);
  44.  
  45.  
  46.  
  47.        
  48.  
  49.         }
  50.  
  51. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Hope it'd help you.... :)
prajkti.khadse
Developer
Developer
 
Posts: 32
Joined: Thu Mar 19, 2009 1:01 pm
Location: Bangalore

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests