global variable ==> Extending Application ???


Last Updated:

  1. aryaxt

    aryaxt Member This Topic's Starter

    Joined:
    Jun 1, 2010
    Messages:
    21
    Likes Received:
    0
    I am trying to implement a class extending the application to keep my global variables. I get an error
    Code (Text):
    1. public class MyApp extends Application {
    2.     public String username;
    3.     public String session;
    4.     public String key;
    5. }
    //when debugging and trying to go through line 6 the debugger says: source not found , and there is a button that says "Edit source lookup path"
    Code (Text):
    1. public class MyActivity extends Activity {
    2. @Override    
    3.     public void onCreate(Bundle savedInstanceState) {
    4.         super.onCreate(savedInstanceState);
    5.         setContentView(R.layout.loader);        
    6.         MyApp app = ((MyApp)getApplicationContext());
    7.         //when debugging and trying to go through the line above the debugger says: source not found , and there is a button that says "Edit source lookup path"
    8.         String username = app.username;
    9.     }
    10. }
     

    Advertisement
  2. aryaxt

    aryaxt Member This Topic's Starter

    Joined:
    Jun 1, 2010
    Messages:
    21
    Likes Received:
    0
    I found the solutionI had to add:
    android:name="MyApp"
    to my manifest file
     
  3. tonylukasavage

    tonylukasavage New Member

    Joined:
    Jun 3, 2011
    Messages:
    2
    Likes Received:
    0

Share This Page

Loading...