Search code examples
androidandroid-intentandroid-activity

Android : how can i get activity value by using intent?


I want to make loading page between activities.
So, I tried to make new Activity only for loading but there is one problem.
I can't get 'Activity' value by using intent like,

 Intent i = new Intent(activity1.this, activity2.class); 
 i.putExtra("Activity", activity1.this);
 startActivity(i);

However, I can't get this Extra value because there is no 'getActivityExtras()'.
How can I do this..?


Solution

  • // define NAME in Activity 1
    public const NAME = "Activity1";       
    
    Intent i = new Intent(activity1.this, activity2.class); 
    i.putExtra("Activity", "Activity1.NAME");
    startActivity(i);
    
    // in Activity 2
    activity = getStringExtra("Activity");
    
    switch(activity) {
     case Activity1.NAME:
     // do whatever you want here
     break;
    

    }