Kayıtlar

android etiketine sahip yayınlar gösteriliyor

Open URL/Website from android

String url = "http://almondmendoza.com/android-applications/"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i);

Brief Introduction on Technologies

TomCat : Tomcat, is an open-source web server developed by the Apache Software Foundation (ASF). Tomcat implements several Java EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a "pure Java" HTTP web server environment for Java code to run in. MongoDB : MongoDB is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster. Released under a combination of the GNU Affero General Public License and the Apache License, MongoDB is free and open-source software. MySQL : MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack (and other "AMP" stacks)...

Launch Main Activity only one time on Android

Use  android:launchMode="singleTop"  to make sure that a new instance of  MainActivity  isn't spawned when you press the back button. Spawning a new instance of  MainActivity  is not memory efficient. Then, in the actual  SettingsActivity  you should override the home button to act like the back button: if (id == android.R.id.home) { onBackPressed(); } and you should display home as up, to  allow up navigation : this .getSupportActionBar().setDisplayHomeAsUpEnabled( true );

Differences between PreferenceChangeListener and SharedPreferenceChangeListener

PreferenceChangeListener  is not the same as a  SharedPreferenceChangeListener The differences are: SharedPreferenceChangeListener  is triggered after any value is saved to the SharedPreferences file. PreferenceChangeListener  is triggered before a value is saved to the SharedPreferences file. Because of this, it can prevent an invalid update to a preference.  PreferenceChangeListeners  are also attached to a single preference. Generally the flow goes like this: User updates a preference. PreferenceChangeListener  triggered for that preference. The new value is saved to the SharedPreference file. onSharedPreferenceChanged  listeners are triggered. Otherwise they act very similarly. In your activity you implement the  Preference.OnPreferenceChangeListener , override the  onPreferenceChange(Preference preference, Object newValue) . The  onPreferenceChange  method will return either true or false, depending on whet...

Register SharedPreference

SharedPreferences sharedPreferences = PreferenceManager. getDefaultSharedPreferences (this); Register the listener sharedPreferences.registerOnSharedPreferenceChangeListener(this); Unregister the listener PreferenceManager. getDefaultSharedPreferences (this)          .unregisterOnSharedPreferenceChangeListener(this);

Creating menu bar on Android

onCreateOptionsMenu()   method should be override. The  showAsAction  attribute allows you to define how the action is displayed. For example, the  ifRoom  attribute defines that the action is only displayed in the action bar if there is sufficient screen space available. <? xml version= "1.0" encoding= "utf-8" ?> <menu xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: app = "http://schemas.android.com/apk/res-auto" > <item android :id= "@+id/action_settings" android :title= "@string/menu_title" app :showAsAction= "never" android :orderInCategory= "100" /> </menu> The   MenuInflator   class allows to inflate actions defined in an XML file and adds them to the action bar.   MenuInflator   can get accessed via the   getMenuInflator()   method from your   activity . The following example code demonstrates the creation of actions. @Overrid...

Question on Lifecycle Events on Android

Resim
What is the order that the lifecycle events are called  after  the device is rotated ? onPause, onStop, onDestroy, onCreate, onStart, onResume Rotating the device causes the Activity to be destroyed and recreated, so our lifecycle starts at onPause and ends at onResume. Note that we don't see onRestart, which only happens if the activity is stopped (but not destroyed) and then restarted. More Info: When we use   onSaveInstanceState, We're missing onStop and onDestroy, because those states happen after onSaveInstanceState is called . We at least see the lifecycle all the way through onSaveInstanceState and you'll see that the TextView gets filled with more logs as you rotate the device more.

ShareCompat.IntentBuilder in Android

IntentBuilder is a helper for constructing  ACTION_SEND  and  ACTION_SEND_MULTIPLE  sharing intents and starting activities to share content. The ComponentName and package name of the calling activity will be included. Source :  https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentBuilder.html A choose dialog appears from the bottom of the screen showing all the apps on the device that are able to handle this type of the intent. // TODO (1) Create a void method called shareText that accepts a String as a parameter public void shareText (String text) { // Do steps 2 - 4 within the shareText method // TODO (2) Create a String variable called mimeType and set it to "text/plain" String mimeType = "text/plain" ; // TODO (3) Create a title for the chooser window that will pop up String title = "First Share Text" ; // TODO (4) Use ShareCompat.IntentBuilder to build the Intent and start the choose ShareComp...

Verify that Intent can be launched

// TODO (1) Create a method called openWebPage that accepts a String as a parameter // Do steps 2 - 4 within openWebPage     // TODO (2) Use Uri.parse to parse the String into a Uri     // TODO (3) Create an Intent with Intent.ACTION_VIEW and the webpage Uri as parameters      // TODO (4) Verify that this Intent can be launched and then call startActivity public void openWebPage(String url){      Uri uri = Uri. parse (url);      Intent intent = new Intent(Intent. ACTION_VIEW ,uri);      if(intent.resolveActivity(getPackageManager()) != null){          startActivity(intent);      } } When you call  startActivity()  or  startActivityForResult()  and pass it an implicit intent, the system  resolves the intent  to an app that can handle the intent and starts its corresponding  Ac...

sample activity in android

package com.example.android.sunshine; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.ProgressBar; import android.widget.TextView; import com.example.android.sunshine.data.SunshinePreferences; import com.example.android.sunshine.utilities.NetworkUtils; import com.example.android.sunshine.utilities.OpenWeatherJsonUtils; import java.net.URL; public class MainActivity extends AppCompatActivity { private TextView mWeatherTextView ; // TODO (6) Add a TextView variable for the error message display private TextView errorTextView ; // TODO (16) Add a ProgressBar variable to show and hide the progress bar private ProgressBar progressBar ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContent...

Override onCreateOptionsMenu to inflate the menu for the Activity

Override onCreateOptionsMenu to inflate the menu for the Activity @Override public boolean onCreateOptionsMenu(Menu menu) { /* Use AppCompatActivity's method getMenuInflater to get a handle on the menu inflater */ MenuInflater inflater = getMenuInflater(); /* Use the inflater's inflate method to inflate our menu layout to this menu */ inflater.inflate(R.menu. forecast ,menu); /* Return true so that the menu is displayed in the Toolbar */ return true ; }

Github query URL (using Uri) and get the response data in Android

/* These utilities will be used to communicate with the network.*/ public class NetworkUtils { final static String GITHUB_BASE_URL = "https://api.github.com/search/repositories" ; final static String PARAM_QUERY = "q" ; /** The sort field. Default: results are sorted by best match * if no field is specified. */ final static String PARAM_SORT = "sort" ; final static String sortBy = "stars" ; /** * Builds the URL used to query Github. * @param githubSearchQuery The keyword that will be queried for. * @return The URL to use to query the weather server. */ public static URL buildUrl(String githubSearchQuery) { // To build the proper Github query URL Uri builtUri = Uri. parse ( GITHUB_BASE_URL ) .buildUpon() .appendQueryParameter( PARAM_QUERY ,githubSearchQuery) .appendQueryPara...

Android Resource Directories

Some Common Resource Types Name What's Stored Here values XML files that contain simple values, such as string or integers drawable A bunch of visual files, including Bitmap file types and shapes. More information is  here layouts XML layouts for your app Other Resource Types Name What's stored here animator XML files for property animations anim XML files for tween animations color XML files that define state list colors mipmap Drawable files for launcher icons menu XML files that define application menus raw Resource file for arbitrary files saved in their raw form. For example, you could put audio files here. (You might also be interested in the  assets folder , depending on how you use that audio) xml Arbitrary XML; if you have XML configuration files, this is a good place to put them More information