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

onSaveInstanceState is not getting called

I have an activity which starts various activities for result codes and on getting results in onActivityResult method it starts appropriate activity based on result code. onSaveInstanceState is not getting called in Activity which started for…
HemangNirmal
  • 621
  • 1
  • 8
  • 24
4
votes
4 answers

startActivity not working

public void onItemClick(AdapterView parent, View view, int position, long id) { //Toast.makeText(getApplicationContext(), "Position of selected item is: "+ position, Toast.LENGTH_LONG).show(); if ("Abiding…
999
  • 83
  • 1
  • 1
  • 9
4
votes
5 answers

onActivityResult for Intent(Settings.ACTION_SETTINGS) called immediately

In my splash screen I have request to server, but when there's no internet connection i'm opening Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS); startActivityForResult(settingsIntent, REQUEST_ENABLE_CONNECTION); But problem is that…
Udi Oshi
  • 6,787
  • 7
  • 47
  • 65
4
votes
2 answers

Android Can you get an activity result from a chained startActivityForResult

I have the following activity screens Activity A - contains a button that links to Activity B Activity B - contains a confirmation of order and then a Next button that opens up a Activity C (to capture signature) Activity C - a dialog box that pops…
4
votes
3 answers

get name of activity within Intent

I am using some various ad networks, they all require their own activity names to be added to the manifest. I want to know when users click them, so I put in an override for startActivity(Intent intent) but I need to inspect the intent object to…
CQM
  • 42,592
  • 75
  • 224
  • 366
4
votes
3 answers

Unable to start activity, setOnClickListener

Can't start new activity. Got problem in onClickListener. I post a code an errors. Have not any idea why I got error in this line. I think it can be not initialized variable Button b, but it's initialized! Help, plz. Code: public class newItem…
Val
  • 4,225
  • 8
  • 36
  • 55
3
votes
3 answers

startActivity and startSubActivity

Can anyone tell me the difference between startActivity and startActivityForResult? Is startActivity used to call Activity asynchronously and startActivityForResult for a synchronous call? Are startActivity(intent) and…
Hunt
  • 8,215
  • 28
  • 116
  • 256
3
votes
0 answers

Android UI Testing, context.startactivity() does not work

I am constructing a Android UI test using UIAutomator, hope to start the target app to be test and do some test actions on the UI. But when I use intent to start the app, it does not work (ie. it does not launch the target app on my real device, but…
3
votes
3 answers

Activity Do not clear from back stack even From Method Intent.FLAG_ACTIVITY_CLEAR_TOP

I want to move to another activity but before i want to clear all the other activity. I know the method Intent.FLAG_ACTIVITY_CLEAR_TOP but it does not work when i back pressed after moving then it again show the previous one activity. My code is …
Muhammad Yaseen
  • 278
  • 2
  • 12
3
votes
2 answers

Notification with setFullScreenIntent not displaying activity when screen is off

I have been trying to show an activity in my app when a notification is triggered and the device screen is off. This activity is a screen for handling an incoming call. So far, this is working with an Android Nougat (Huawei P9 lite) device, but not…
3
votes
4 answers

startActivity in java class crash

I'm developing an Android app for a school project and i have the following problem. I have a MainActivity with a Button and a SecondActivity. When I click on the button in the MainActivity it have to open the SecondActivity. I tested it on my two…
Steve
  • 33
  • 3
3
votes
1 answer

Android UIAutomator/espresso: open browser on a specific URL

I'm playing around with UIAutomator/espresso and my application. Actually I would like to do the following: Do some action/check on my application Open the default browser to a URL Go back in my application and recheck the interface Actually I…
3
votes
1 answer

Share intent takes long time to appear

I'm trying to include image sharing in my application and everything is working but the share chooser takes long time to appear on devices here is what i'm doing: I have ImageView "items_details_image" and I want to share its image to be able to…
3
votes
5 answers

Start Activity from within ArrayAdapter

I have a custom adapter that extends ArrayAdapter. I want to go to MapActivity when the EMAIL is clicked. If I remove the intent part a toast appears with the correct position of the item clicked. However, if I add the startActivity function, the…
ankit
  • 125
  • 4
  • 13
3
votes
2 answers

startActivityForResult for Notification Listener

Is it possible to get a result from the notification listener Settings screen? Currently, my project is using startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")); I tried using startActivityForResult but was unable…
1 2
3
31 32