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

startActivity method doesn't launch the new activity in real device

I am a beginner in Android. I am trying to start a new activity via an intent inside an onclick event. This works fine in emulator. But when I try it in a real device it doesn't work and the application goes to the main screen again. No errors are…
0
votes
1 answer

back button not returning to previous activity

My small test app is a ListActivity which displays all the contacts. When the user clicks one, it opens the "people" ACTION_EDIT activity. This works fine. When the user clicks "back" or finishes editing in some other way, the main "People" list…
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
0
votes
4 answers

onactivityforresult not called after contactscontract action_edit

I have a ListActivity which displays all the aggregate contacts. When the user clicks one, my code calls startActivityForResult. All this works properly. When the user finishes editing, I want my ListActivity to be displayed again. Instead, the…
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
0
votes
1 answer

Unable to start activity in android...?

As i am new to android development i am struck up with a problem in my project. Code is.. for processing webservice code i am calling webinterface class from main.java file as follows. Main.java @Override public void onCreate(Bundle…
user1578518
0
votes
1 answer

how to launch default android gallery without startActivityForResult

as in the title, but i don't need to return anythimg! just open a gallery.. i tried with Intent intent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); intent.setAction(Intent.ACTION_VIEW); …
kekko986
  • 81
  • 2
  • 8
0
votes
4 answers

Null intent returned to previous Activity after changing orientation

I'm facing this strange issue: I'm using startActivityForResult() to pass to the next Activity. In the second Activity everything is fine until I start changing the phone orientation, which cause some problem when going back to the previous…
ColdFire
  • 6,764
  • 6
  • 35
  • 51
0
votes
1 answer

Starting a no launcher activity from another package

I try to start an activity from another package, but it has not LAUNCHER category Intent i = new Intent(); i.setComponent(new ComponentName(maxVerPackageName, maxVerClassName)); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); …
hamid toosi
  • 95
  • 1
  • 10
0
votes
4 answers

Avoid loading data again when finishing activity

In my main Activity of the app, I download some user data at the onStart(). When I open the Settings and I hit the Back button, I finish the Settings Activity and I return to the main Activity. The problem is that the data is being…
anonymous
  • 1,320
  • 5
  • 21
  • 37
0
votes
2 answers

how I start activity which is caller and close activty which is callling at same time?

I want to call a activty but when I call actviy I want to finish my caller activty , How can I do this? A:caller B:calling startActivity(new Intent(A.this, B.class)); finish(); I write this code but everything is closing.
user1474138
0
votes
1 answer

android:parentActivityName vs onBackPressed startActivity

In Android application, does somebody know what is the difference between : override onBackPressed in an Activity and startActivity vs put "android:parentActivityName" in manifest in the activity tag Thanks
user1503892
  • 9
  • 1
  • 1
-1
votes
1 answer

Android app exits when launch another activity using registerForActivityResult

I have 2 classes MainActivity and EditActivity. I try to launch EditActivity with registerForActivityResult() in MainActivity but the app exits immediately; startActivity() works fine but registerForActivityResult() serves my purpose, which is…
-1
votes
3 answers

Can't get back to main activity in Android studio

In my project I have two activities: MainActivity.class and SecondActivity.class. To switch from the MainActivity to the SecondActivity I use the following code: Intent intent = new Intent(MainActivity.this,…
-1
votes
2 answers

startactivity creates two instances

for my android app, I use a button to go to the next Activity. the problem is when I touch the button on the screen one instance of the activity is created but when I use performClick() method to click the button programmatically, it creates two…
agoufx
  • 49
  • 4
-1
votes
1 answer

The startActivity () method returns an error. / Fragment - Android

I have two classes that are covered by fragment. The startActivity () method returns an error. When my button named btn in my home.java class is clicked.   I want to click on my button named btnctwo in my class named hometwo.java. but i get an…
user606
  • 15
  • 5
-1
votes
1 answer

Receive data from other apps using WebIntent in Ionic 4 or 5

ionic plugin add https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent --save the above plugin added to my ionic app after that, I am unable to build the apk in ionic framework and please suggest me how to receive data from other…