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

Cannot launch an activity in android using intent

I have 2 modules in my application as follow app and interface. interface was an imported aar file. I am trying to launch an activity in the interface module but every time the application crashes. Launching activities on the app module works fine…
-1
votes
2 answers

Creating Intent using an ArrayList

So I have an ArrayList, and I would like to create intent and switch activities using this piece of code (in ListAdapter class): for (int i = 0; i <= activityList.size(); i++){ if (position == i){ Intent intent = new Intent(context,…
-1
votes
2 answers

Secret login Password - Android

The goal of my code is: when I type a secret username and password, then, press enter button, open a Activity3. otherwise, open Activity2. This is my code: package edcomp.terraraimoveis; import android.app.Activity; import…
-1
votes
2 answers

startActivity in onclick

have a simple Activity with a onClick method - it works but Android Studio marks startActivity red says cannot resolve method - so why? @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Chad White
  • 309
  • 1
  • 4
  • 15
-1
votes
1 answer

start activity intent - bring to front if running or ignore intent

I want to bring another app to front if it is running already, otherwise I don't want to do anything. Normally I start the other app like following: ComponentName compName = new ComponentName(packageName, activityName); Intent i = new…
prom85
  • 16,896
  • 17
  • 122
  • 242
-1
votes
2 answers

How to finish an activity from a class in android

i have three Activities A , B and C ; The Activity C above the activity B and B above A . class A : button.setonclicklistener... . . .{ startactivity(A.this , B.class() ) ; } . . .} class B :…
Redouane
  • 1
  • 1
-1
votes
2 answers

How to start an Activity from AsyncTask?

I've build an AsyncTask and want to start another Activity when it ends (onPostExecute) but it won't work and I can't find the problem. Maybe there is a problem with String, String, String ? Here is my code: public class StartSearch extends…
-1
votes
7 answers

Unable to stop my application from going back to login activity no matter what i do

This is giving me a hard time, no matter what i do pressing back button return the application to login activity. These are the methods is I've tried so far: 1: I tried to set intent flags to clear top, erase history and also exclude the activity…
-1
votes
1 answer

EditText does not return to ListView

I have two Activity, A and B. In A, it has a listView and a button. In B, it has imageView and editText . Now what I trying to achieve is return the text from B to listView A. Activity A View claims = inflater.inflate(R.layout.receipt_text,…
Hoo
  • 1,806
  • 7
  • 33
  • 66
-1
votes
2 answers

Which bundle should be used to pass an object

I would like to pass an object from an activity to a fragment. I know how to pass the data but do not know which type of bundle i should use? UPdate In other words, I have an object of type mqttAndroidClient and that object i want to pass from my…
rmaik
  • 1,076
  • 3
  • 15
  • 48
-1
votes
1 answer

Android startActivity() isn't working inside for-loop

I really can't see the problem on my code. The startActivity() method is not working in the code below. Even Toast.makeText() does not work. If I put the toast before the for-loop it works, but I cannot put startActivity before for-loop because…
-1
votes
1 answer

Android SearchView: startActivity() gets called twice

The architecture is the following: 1) MainActionBarActivity - base class, which implements the ActionBar behavior, i.e. overriding onCreateOptionsMenu(), onOptionsItemSelected(), onSearchRequested() and startActivity() 2) HomeActivity extends…
Addicted
  • 11
  • 3
-1
votes
1 answer

How to start startActivityForResult() from a BroadcastReceiver class?

My main class is a BroadcastReceiver class. I want to use startActivityForResult() from the BroadcastReceiver class. But it is not possible to call startActivityForResult() from a BroadcastReceiver class. So that can i call another activity class…
-1
votes
1 answer

Using Intents for communicating between apps

Below is a simple way to communicate from App A to App B // Call from App A Intent intent = new Intent("some.Activity.inAppB"); startActivityForResult(intent, 0); Now in the above statement, I want to trace from AOSP if the activity being called…
Adi GuN
  • 1,244
  • 3
  • 16
  • 38
-1
votes
3 answers

startActivityForResult annoying behaviour

I have the following case When press a button I startActivityForResult , it opens another activity with dialog theme and show a list of linear layouts, and when I press on the linear layout I finish the activity on the onClick Listener but the…
Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175