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
85
votes
3 answers

How to start activity in another application?

I have application A defined as below:
user256239
  • 17,717
  • 26
  • 77
  • 89
82
votes
3 answers

Start new Activity and finish current one in Android?

Currently I'm starting a new Activity and calling finish on a current one. Is there any flag that can be passed to Intent that enables finishing current Activity without a need to call finish manually from code?
pixel
  • 24,905
  • 36
  • 149
  • 251
64
votes
9 answers

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode

I am writing an application where Activity A launches Activity B using startActivityForResult(intent, -101); but when called, it responded back with following error log: E/AndroidRuntime( 1708): java.lang.IllegalArgumentException: Can only use…
CoDe
  • 11,056
  • 14
  • 90
  • 197
51
votes
2 answers

Difference between startActivityForResult() and startActivity()?

What is the difference between startActivityForResult() and startActivity() ? When, and for what, should I use each one ?
22
votes
2 answers

Wrong requestCode returned onActivityResult from another Activity

I have an Activity that calls another Activity, that calls some other Activities. I send to the last Activity to get a result, and then i send back the result to the fist Activity. The flow is somthing like A -> B -> C -> D -> C -> B -> A With the…
Luca
  • 823
  • 4
  • 11
  • 31
20
votes
1 answer

Android - AssertionFailedError on startActivity method in ActivityUnitTestCase test class

I am trying to test an activity in a module. I am just trying to start this activity in the test method, but I always have a AssertionFailedError. I searched the web for this issue but could not find any solution. Any help is appreciated. This is my…
19
votes
9 answers

White screen is displayed while switching between Activities

When I move from one Activity to another Activity, a white screen is displayed for 2 seconds. I am using this code: Intent intent = new Intent(this, SecondActivity.class); startActivity(intent); How can I resolve this issue?
16
votes
2 answers

StartActivityForResults always returns RESULT_CANCELLED for Intent.ACTION_SEND

As the share pop up appears, I shared the content on WhatsApp successfully, but still returns RESULT_CANCELLED. Same result when I send a email using Gmail. Calling Sharing intent, ACTION_SEND with startActivityForResult always returns…
Siddharth
  • 9,349
  • 16
  • 86
  • 148
14
votes
6 answers

resultCode is always 0 and request is always -1, . Activity.onActivityResult();

I would like to add this to another list of questions about resultCode == 0 and requestCode == 0. Here is the synopsis: NoteActivity calls NoteSettingsActivity using startActivityForResult(). I have searched the web and when I pressed back button…
Neon Warge
  • 1,817
  • 6
  • 29
  • 53
13
votes
3 answers

Can't start activity from BroadcastReceiver on android 10

I updated my OS version to android 10 last night, and since then the startActivity function inside the broadcast receiver is doing nothing. This is how I try to start the activity based on the answer of CommonsWare: Intent i = new Intent(context,…
10
votes
1 answer

ACTION_INSTALL_PACKAGE

My app is trying to install an APK. Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); installIntent.setData(Uri.fromFile(new File(pathToApk))); installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE,…
Akh
  • 5,961
  • 14
  • 53
  • 82
8
votes
1 answer

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.USAGE_ACCESS_SETTINGS }

This issue is happening on Android 5.0 Lollipop only. I dont have access to a phone with Lollipop, I have developed the code in Genymotion Android Emulator but this issue does not happen in the emulator. I am only getting failing stacktraces from…
user1406716
  • 9,565
  • 22
  • 96
  • 151
7
votes
2 answers

How pass data between activities using RxJava in android?

I need to pass some data between two activities MainActivity and ChildActivity. Button click on MainActivity should open ChildActivity and send event with data. I have singleton: Subject subject = new…
7
votes
2 answers

How to Pick Image From Google Photos App Only? Android Google Photos Intent

I am trying to get an image directly from the Google Photos app. I wish to bypass the app chooser usually started when using Intent.ACTION_GET_CONTENT and instead go directly to Google Photos if the user has it installed and allow the user to select…
Michael Garner
  • 1,042
  • 1
  • 10
  • 19
7
votes
2 answers

Open a fragment of an activity from another activity

Hi All I want to open the "Text-To-Speech output" fragment of Settings from my application. I think first I need to open the settings activity and then its fragment. I tried setting the ComponentName but it was unable to locate the activity. Should…
1
2 3
31 32