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
2
votes
2 answers

Difference between startChooser() method and startActivity()

I'm new to android and i have noticed that i can share an intent in 2 ways. first way : ShareCompat.IntentBuilder.from(this). setType(mimeType). setChooserTitle(title). setText(text). …
Abdel-Rahman
  • 539
  • 5
  • 19
2
votes
1 answer

Activity reopening is working only once

I have receiver and when some action is happening I need to reopen current activity(I am in HideSettingsActivity and I want to close that Activity and open the new one HideSettingsActivity). For this I'm just finishing current activity and open the…
2
votes
0 answers

Video free multi window size is not changed in android 7.1

I'm working on free multi window in android 7.1. With test application free multi window is working perfect.(please fine screenshot 1) Now Im playing video using MX player app, at that time free multi window size is not effecting.(please fine…
GNK
  • 1,036
  • 2
  • 10
  • 29
2
votes
1 answer

How I can use startActivity method from service in python kivy/jnius?

I want to start an activity from a service in my android application (python 2.7 & kivy). I use startActivity method for it but it's not work. When I run the app and type "buildozer android logcat", I see this: File "jnius_export_class.pxi", line…
Alexander
  • 21
  • 3
2
votes
1 answer

How do i create a custom start activity method in android?

I want to create a method to start multiple activities. I have set setOnClickListener on every button. I have implemented onClick() method that looks like this: public void onClick(View view) { switch (view.getId()) { case…
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
2
votes
3 answers

Error when trying to open new activity from menu

I'm trying to move to a new activity from a selected option from a menu on my main screen. The code for doing this is public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.action_settings: …
user616076
  • 3,907
  • 8
  • 38
  • 64
2
votes
1 answer

Activity With TabLayout Save State After New Activity Start

I have an Activity that contains a TabLayout linked to a ViewPager. The ViewPager contains three fragments, and each fragment has a RecyclerView containing a list of articles. When you click on an a list item, it starts a new Activity with the full…
2
votes
0 answers

Timeout parent activity after a given interval

I have a child activity. I then call: Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); startActivity(intent); If the user doesn't do anything for 60 seconds, I want to return to the child activity to do something else. However…
2
votes
1 answer

Unknown error while trying startActivity from BaseAdapter

I am doing custom ListView in android and I have a share button on each item. After clicking button it must create chooser(facebook, etc). But when I click it the app crashes and logcat shows nothing. Please help me Here is my Adapter: public class…
2
votes
0 answers

start an activity through a method of the class that will be responsible for the running starActivity

good afternoon I have two classes, one that implement one progressBar this class I intend to create a public method that will run startActivity(). the main class would have a button that would call the method. However this giving error null…
user4420225
2
votes
2 answers

Espresso : test startActivityForResult return RESULT_OK

I got an Android app that requires authentication to be used. As the project grows up, I want to add unit testing in my app. To do that, I use Espresso 2.1 The thing is: My LoginActivity is called by startActivityForResult It shows the form a. If…
Quentin Klein
  • 1,263
  • 10
  • 27
2
votes
4 answers

How to return to activity after sending a mail in android?

All working fine and the mail is also properly sending .But I cant return to the activity after sending mail. Current screen history is false.I have used start Activity with result code also.But cant make it. Could some one guide or provide some…
Deepak
  • 192
  • 1
  • 2
  • 18
2
votes
2 answers

startActivity(intent) is not opening activity

I'm making an android app with 2 activities and a Java class that reads/writes RFID data using NFC. I'm using the enableReaderMode() method to enable reader/writer mode in the mainActivity, which then calls onTagDiscovered in a separate java class.…
mofitty
  • 111
  • 1
  • 3
  • 10
2
votes
0 answers

Viewpager - setCurrentItem(1), the fragment parent fragment doesn't get onActivityResult() when child fragment calls startActivityForResult

So I have a nested Fragment and view pager scenario. I have an activity that loads ParentFragment. ParentFragment has a ViewPager that has 4 fragments. Normally the view pager starts at 0. But because I want to help the user return back to their…
2
votes
1 answer

send message directly to whatsapp using context.startActivity

I want to send a message directly via whatsapp and I find the code below working. But it does not work and crash after I move the code into another java file as a common function call. So what is wrong? Thanks before: Intent sendIntent = new…
user2911996
  • 63
  • 1
  • 2
  • 10