Questions tagged [start-activity]

Launch a new Activity by using Intent in Android.

This public method launches a new Activity and use an Intent. An Intent is an object that provides runtime binding between separate components (such as two activities). The system receives this call and starts an instance of the Activity specified by the Intent. You will not receive any information about when the activity exits.

For example, you are in ActivityA and want to launch ActivityB. You do as follows:

// Create a new intent with current activity and new activity
Intent intent = new Intent(Activity1.this, ActivityB.class);
// Call startActivity to launch the new activity with intent
startActivity(intent);  

An Intent can pass datas to new Activity, see Start the Second Activity topic from Google Documentation. Also, you can use the method startActivity(Intent, Bundle) where Bundle is additional options for how the Activity should be started.

Note: You must declare the new activity in your Manifest file as the old one, like the following example:

<activity 
    android:label="@string/app_name"
    android:name="com.package.name.ActivityB" />

About this method, see the startActivity(Intent intent) Documentation
And the SO question How to start new activity on button click
Related tags: , , ,

470 questions
-4
votes
2 answers

Error:Expression expected

Intent danielIntent = new Intent(Broadcast.this, Broadcasting.class); danielIntent.putExtra(String,"Free Loop"); startActivity(danielIntent); There is an error said expression expected,I don`t what should do next.
William Liu
  • 9
  • 1
  • 1
-4
votes
1 answer

How to check whether the received intent contains String or int

My activity receives two intent from two different activity. One intent contains int value with extras and another contains String. I want to distinguish both intent in receiver activity. Is there any way to check if the received intent has int…
Apurva
  • 7,871
  • 7
  • 40
  • 59
-5
votes
1 answer
-5
votes
3 answers

Solve startActivity in fragment

I have a problem in my code. My problem is related to the startActivity(). When the app is running on the emulator, it does not work. The line causing the problem is described in the end. I tried to open a new activity (this, newactivity.class),…
YVLM
  • 53
  • 1
  • 2
  • 5
1 2 3
31
32