

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Study notes for Mobile 1, these notes are for Android and not iOS.
Typology: Study notes
1 / 25
This page cannot be seen from the preview
Don't miss anything!
views.
or to perform work for remote processes. (A service does not provide a user interface.)
provider.
(Intents).
zone has changed, that the battery is low, SMS has been received, etc.
some data has been downloaded to the device and is available for them to use.
to be completed.
UI components and activity behaviors into modules that you can swap into and out of your activity.
nested activity that can define its own layout and manage its own lifecycle.
with other fragments inside an activity to modify your layout configuration for different screen sizes.
background and does not provide a user interface.
background even if the user switches to another application.
process communication (IPC).
or interact with a content provider, all from the background.
■ A service is “started” when an application component (such as an activity) starts it by calling startService().
■ Once started, a service can run in the background indefinitely, even if the component that started it is destroyed.
■ A service is “bound” when an application component binds to it by calling bindService().
■ A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with inter process communication (IPC).
■ A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.
■ The system calls this method when another component, such as an activity, requests that the service be started, by calling startService().
■ The system calls this method when another component wants to bind with the service by calling bindService().
■ The system calls this method when the service is first created.
■ The system calls this method when the service is no longer used and is being destroyed.
mechanism.
■ Shared preferences are private data stored in key value pairs.
■ Internal storage is a location where you can save files on the device’s internal storage (NAND Flash).
■ By default, files stored in internal storage are private to your application, and other applications cannot access them *neither can the user of the device.)
■ When the user uninstalls the application, the private files are removed.
■ Every Android device supports shared external storage that you can use to store files.
■ This can either be the removable storage such as a Secure Digital Card (SD Card) or non-removable internal storage (NAND).
■ Android supports the full use of SQLite databases.
■ You can create tables and perform SQL queries against the tables accordingly.
■ If you’d like to cache some data rather than store it persistently, the internal data directory is where you should create the cache.
■ If you store data here and the system gets low on internal storage space, Android may delete these files to reclaim space.
■ You should stay within a reasonable limit of space consumed of around 1MB.
■ This can be any remote data source that you have access to.
■ For example, Flick exposes an API that allows you to store images on its servers.
■ Your application could work with Flickr to store your images.
device.
is inspected for required permissions that the application needs to operate.
AndroidManifest.xml file in your project.
and strings.
process, by default
slowing down the user interface
components running, the Android system starts a new Linux process for the application with a single thread of execution.
(called the “main” thread).
applications should not change this.
to, you can do so in the manifest file.
eventually needs to remove old processes to reclaim memory for new or more important processes.
into an “importance hierarchy” based on the components running in the process and the state of those components.
importance, and so on, as necessary to recover system resources.
types of processes in order of importance (the first process is most important and is killed last):
■ It hosts an Activity that the user is interacting with (the Activity’s onResume() method has been called).
■ It hosts a Service that’s bound to the activity that the user is interacting with.
■ It hosts a Service that’s running “in the foreground” – the service has called startForeground().
■ It hosts a Service that’s executing one of its lifecycle callbacks (onCreate (), onStart(), or onDestroy()).
■ It hosts a BroadcastReceiver that’s executing its onReceive() method.
■ It hosts an Activity that is not in the foreground, but is still visible to the user (its onPause() method has been called).
■ It hosts a service that’s bound to a visible (or foreground) activity.
as network access or database queries will block the whole UI.
worker thread – you must do all manipulation to your user interface from the UI thread.
whose result is published on the UI thread.
must include the following permissions:
import java.util.Calendar;
import android.os.Bundle; import android.os.Handler; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView;
public class Token_Main_Activity extends Activity implements OnClickListener { // Initializes constants, variables, intents, handlers and views. final int X = 1245; final int Y = 10000;
Intent verify; private Handler handler;
Calendar cal; TextView Passcode, Time; static int passNumber , min , sec ; boolean Running = true ;
@Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. token_main_layout ); setupVariables(); setupThread(); generatePasscode(); }
// Sets up handlers, intents & views. public void setupVariables() { verify = new Intent( this , Token_Verify. class ); handler = new Handler(); Passcode = (TextView)findViewById(R.id. textView3 ); Time = (TextView)findViewById(R.id. textView4 ); }
// Generates the passcode. public void generatePasscode() { cal = Calendar. getInstance (); min = cal.get(Calendar. MINUTE ); passNumber = min * X + Y; Passcode.setText("" + passNumber ); }
// Starts the Verify activity when clicked. @Override public void onClick(View V) {
switch (V.getId()) { case R.id. bVerify : startActivity(verify); break ; }
}
// Worker thread constantly running in the background, updates seconds & local passcodes. public void setupThread() { Runnable runnable = new Runnable() { @Override public void run() { while (Running) { try { Thread. sleep (1000); } catch (InterruptedException e) { e.printStackTrace(); }
handler.post( new Runnable() { @Override public void run() { cal = Calendar. getInstance (); sec = cal.get(Calendar. SECOND ); Time.setText("" + (60 - sec ));
if ( sec == 0) generatePasscode(); } }); } } };
new Thread(runnable).start(); } }
package token.biamonte.ass4;
import java.io.BufferedReader;
connMgr = (ConnectivityManager)getSystemService (Context. CONNECTIVITY_SERVICE ); accepted = MediaPlayer. create ( this , R.raw. accepted ); rejected = MediaPlayer. create ( this , R.raw. rejected ); passcodeApp = (TextView)findViewById(R.id. tvPassApp ); passcodeServ = (TextView)findViewById(R.id. tvPassServ ); Check = (Button)findViewById(R.id. bFinish ); }
// Obtains the passcode from the server, then compares it to the locally generated passcode. public void checkPasscode() { URL[i] = new getHttp(); URL[i].execute("http://faculty.tru.ca/helmiligi/pass.php"); i++; }
// Checks if the application is connected to the internet. public void checkConnection() { NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) Toast. makeText ( this , "Network is connected..", Toast. LENGTH_SHORT ).show(); else Toast. makeText ( this , "Network is NOT connected..", Toast. LENGTH_SHORT ).show(); }
// Finishes this activity when clicked. @Override public void onClick(View V) { switch (V.getId()) { case R.id. bFinish : this .finish(); break ; }
}
// getHttp subclass, uses the Apache HttpClient. public class getHttp extends AsyncTask <String, Void, String> {
// Initializes variables. HttpClient httpclient = new DefaultHttpClient(); HttpPost post; HttpResponse response; HttpEntity entity; String url, result; int passcode;
// Downloads files in a worker thread. @Override protected String doInBackground(String... arg0) { url = arg0[0]; post = new HttpPost(url); try { response = httpclient.execute(post); entity = response.getEntity();
if (entity != null ) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); instream.close(); } } catch (Exception e) {}
return result; }
// Converts html / php strings to proper strings, then compares passcodes. @Override