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
6
votes
13 answers

How can I send message to specific contact through WhatsApp from my android app?

I am developing an android app and I need to send a message to specific contact from WhatsApp. I tried this code: Uri mUri = Uri.parse("smsto:+999999999"); Intent mIntent = new Intent(Intent.ACTION_SENDTO,…
Johny Moo
  • 63
  • 1
  • 1
  • 6
6
votes
3 answers

startActivity() doesn't work when app is in background (In this special case)

I'm trying to bring my app from background to foreground. In onHandleIntent() of my custom IntentService class, I have: Intent intent = new Intent(); intent.setClass(getApplicationContext(), MainActivity.class); // Also tried with "this" instead of…
6
votes
0 answers

Widget stops responding to clicks (widget freezes)

I have simple app with widget. Widget works good for some time. After open and close another app (e.g. some game for the most cases) my widget stops responding to clicks. Do you know how to fix widget freezing please? I folowed some similar…
Vojtech Pohl
  • 111
  • 7
6
votes
2 answers

onActivityResult in dialog fragment

I'm taking photo from dialog fragment. And also I need something like startActivityForResult(takePictureIntent, actionCode); @Override public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { …
MSr
  • 288
  • 1
  • 6
  • 14
6
votes
1 answer

Open Contact Picker with a Filter

It is easy to open the Android Contact App to show all contacts and pick one of them: in Activity: private int PICK_CONTACT = 853456; // ... // open contact list void openContactPicker() { Intent it= new…
Gisela
  • 1,194
  • 2
  • 16
  • 30
5
votes
0 answers

Android12 - StartActivity not working post Picture-in-Picture mode Expansion

I am working on an App which uses Android's Picture-in-Picture Mode. The MainActivity has a button which launches some other activity(simply fire intent to another Activity). The issue occurs when i enter the PIP Mode and expands the MainActivity,…
5
votes
2 answers

Start activity from receiver in Android Q

I'm checking my app with the Android Q [beta 6] in order to add all the required changes to be fully-compatible with the last SO. However, I found out that I am using a Receiver to start an Activity from background and due to the last background…
5
votes
2 answers

this@MainActivity vs MainActivity@this in kotlin

As you may see that this@MainActivity or MainActivity@this is valid while starting activity in kotlin. I tried to find out answer but I did not found anything. Can anyone know about exact difference of it and which one valid ? Why it allowed both ?
Smeet
  • 4,036
  • 1
  • 36
  • 47
5
votes
2 answers

startActivity in onPause() not working after opening new app

I Start a second activity when my first activity is paused. FirstActivity.java @Override public void onPause(){ super.onPause(); startActivity(new Intent(this, SecondActivity.class)); } When I press on the homescreen button, SecondActivity…
5
votes
4 answers

How to pass non parcelable objects to from activity to another activity?

I have two objects instantiated from two different class and both classes do not implement parcelable nor serializable. and I want to pass those objects to another activity, so I wrote the below code: *code: //send object Intent intConnect = new…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
5
votes
1 answer

Android Custom Launcher startActivity() blocks BOOT_COMPLETED intent

I am currently working on a custom ROM (based on CyanogenMod 11.0), which aims to implement a custom "Kiosk Mode". To do this, I have three components in one application (with system privileges): The service, which handles modifications to the…
5
votes
3 answers

How to get startActivityForResult on external Activity to work?

Searching high and low has yielded no result for my problem. Hence I'm finally posting to plead for some assistance. I have two app, both written by me. App A launches App B, passing in parameters through Intent.putExtra(). This works perfectly fine…
Lf3T-Hn4D
  • 51
  • 1
  • 5
4
votes
1 answer

Best practice to implement startActivity using ViewModel in Jetpack Compose

For example, I have this simple Composable function @Composable fun TextExample(model: SomeViewModel = viewModel()) { TextButton(onClick = { model.onClick() }) { Text(text = "Test") } } The SomeViewModel: class SomeViewModel :…
4
votes
1 answer

How to switch between Android apps programmatically

I want to switch quickly between two running Android apps, a Client and a Server, for debugging purposes. The two are connected by a socket connection. Ideally, I'd like to add a button to both to toggle to the other (preserving the connection) so…
4
votes
3 answers

Chrome CustomTab error: java.lang.NoSuchMethodError: No static method startActivity

I am trying to connect fitbit with my app using chrome custom tabs. But I am getting following error. java.lang.NoSuchMethodError: No static method startActivity(Landroid/app/Activity;Landroid/content/Intent;Landroid/os/Bundle;)V in class…
1
2
3
31 32