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
3
votes
1 answer

Not able to start activity within if statement?

There is a normal flow of activities in my application. If there is an instance where the app crashes / the user force closes the app, I make sure the app goes to the previous activity where the user last was. I record that in a preferences file,…
LoveMeow
  • 3,858
  • 9
  • 44
  • 66
3
votes
5 answers

NullPointerException When starting new Activity in Navigation Drawer

I am using a template navigation drawer that was provided by android studio. I am very new to android development so i'm wondering if i'm missing something simple here. I want to start a new activity by clicking on an item in my navigation menu I…
3
votes
1 answer

Open android intent using a specific application(package name known)

My problem is that I have an intent such as this one. Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH); intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE); …
KISHORE_ZE
  • 1,466
  • 3
  • 16
  • 26
3
votes
1 answer

StartActivityForResult - check for existence of intent extra or use custom result code?

I have a search button in MainActivity which launches SearchActivity. In SearchActivity, the user can either choose from one of the predefined categories listed, or can enter in a search query. The SearchActivity will return a different extra…
mannykary
  • 812
  • 2
  • 10
  • 18
3
votes
1 answer

Start default Android wallpaper chooser

I'm trying to start default android wallpaper chooser. I'm using: Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER); startActivity(intent); This code works but it opens app chooser. I want to open "Wallpapers" directly. My minSdkVersion…
movil
  • 33
  • 4
3
votes
1 answer

Importing Contact .VCF to phonebook android

I am creating a app where i need to backup and restore contacts programmatically to and from my website. Here i have completed one part(backup contacts). In the other part(importing contacts) i use this code. Intent intent = new…
Jay Vyas
  • 2,674
  • 5
  • 27
  • 58
3
votes
2 answers

Code flow using startActivityForResult()

I'm working on an Android app. I have an Activity that checks to see if an XML file exists on my device. If it doesn't exist, I call a routine that does a bunch of stuff, including downloading that file from a URL. If it does exist, I want to prompt…
Chuck
  • 203
  • 6
  • 16
3
votes
3 answers

Start Activity for result

It may be a noob question but I have some doubt. I googled a lot but found nothing. In starting activity for result we pass request code and on result we check with the same request code and result code. I want to know Is there a way to Implement to…
Aduait Pokhriyal
  • 1,529
  • 14
  • 30
3
votes
1 answer

Why is my main activity blackscreen/hidden when returning from another activity?

My app uses the ES File Explorer for loading/saving files using the com.estrongs.action.PICK_FILE intent. It goes to the browser ok does its' stuff and returns the result but on returning to the main activity, the main not visible. It is focused. I…
user960914
  • 197
  • 1
  • 3
  • 12
3
votes
2 answers

startActivity on foreground application causes onPause/onResume

I have a service running and listening on a socket. This service will start an activity to display a video frame when it receives a "format" message over the socket each video frame is then sent in succession. Body of MyService: (simplified and…
Zoccadoum
  • 862
  • 1
  • 10
  • 16
2
votes
1 answer

Android - open Telegram specific account from my own Android app

I am trying to open Telegram app with needed contact and I tried two diffrent ways and noone is not working. First way: I got userId, for example 1111111111 and if I open it from WEB it works fine: https://web.telegram.org/#/im?p=u1111111111, but…
2
votes
1 answer

Android app crashes when I use startActivity method, handleWindowVisibility: no activity for token android.os.BinderProxy@e4f69f5

I am making android app by using Firebase. Firstly I login with email and password. Then I create room successfully. I want to switch to the transaction scene after I create room. Hovewer, when I use startActivity method to switch to the other…
2
votes
2 answers

How to open same Activity with different data in Android Kotlin?

class FirstActivity : AppCompatActivity() { companion object{ val USER_KEY="FirstActivity" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) …
2
votes
5 answers

How can I pass an Intent to the main thread using "startActivity" from a secound thread?

I want to use an Intent with start(Intent) and do different things controled by a Thread. I know I need the main Context to use "startActivity" but how do I manage this from a seperate Thread? is it possible to link the "startActivity" to the main…
Alpha-Centauri
  • 316
  • 2
  • 13
2
votes
1 answer

startActivity not working after class switch

I want to start an activity and give out a Toast message after I parsed a JSON response. public class Sign_Up extends AppCompatActivity { .... register(); public void register() { final String url = "someURL"; new…
Tester2
  • 57
  • 1
  • 9