activity
Launching new activities with intents
In Android you will frequently come up will a need to launch a new Activity from inside your own Application. This is important when you want your Application to have multiple Activities. It is also very useful when you want to use an existing Activity in your system. New Activities are usually launched using Intents.
So, in order to launch new Activities you have to:
package com.javacodegeeks.android.apps.moviesearchapp; import java.util.ArrayList; import android.app.ListActivity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import com.javacodegeeks.android.apps.moviesearchapp.model.Movie; public class MoviesListActivity extends ListActivity { private static final String IMDB_BASE_URL = "http://m.imdb.com/title/"; private ArrayList>Movie> moviesList; private ArrayAdapter<Movie> moviesAdapter; @SuppressWarnings("unchecked") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.movies_layout); moviesList = (ArrayList<Movie>) getIntent().getSerializableExtra("movies"); moviesAdapter = new ArrayAdapter<Movie>(this, android.R.layout.simple_list_item_1, moviesList); setListAdapter(moviesAdapter); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Movie movie = moviesAdapter.getItem(position); String imdbId = movie.imdbId; if (imdbId==null || imdbId.length()==0) { longToast(getString(R.string.no_imdb_id_found)); return; } String imdbUrl = IMDB_BASE_URL + movie.imdbId; Intent imdbIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(imdbUrl)); startActivity(imdbIntent); } public void longToast(CharSequence message) { Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } }
This was an example on how to Launch new Activities with Intents in Android.
Related Article: