La prima app android che andremo ad analizzare è Hello World, ci servirà per capire la struttura base di qualsiasi app. Questa è la struttura della nostra app.
Nella cartella manifest troviamo il file AndroidManifest.xml raccoglie le informazioni basilari sull’app utilizzate in fase di installazione. In questo file troviamo le due activity utilizzate con l’indicazione dell’activity principale (nel nostro caso è SplashHelloWorld).
La cartella drawable contiene le immagini utilizzate dall’app, notiamo che esistono 7 versioni dello stesso file “hello_world” sara’ il dispositivo a scegliere quella adatta alla propria risoluzione.
La cartella values contiene delle costanti utilizzate, vengono divise in: colors, dimens, strings e styles.
Notiamo che styles ha un file generico ed uno se la lingua impostata nel dispositivo è l’italiano
La cartella layout contiene i file che definiscono la struttura delle interfacce utente, nella nostra app abbiamo creato due layout:
una layout che si apre appena viene lanciata l’app e dopo un pò passa al layout principale dell’app.
Il codice della nostra app lo troviamo nella cartella java
SplashHelloWorldActivity.java
definiamo la classe un’estensione della classe Activity
public class SplashHelloWorldActivity extends Activity{
onCreate viene invocata quando l’activity viene create, serve per la fase di inizializzare.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashhelloworld);
View decorView = getWindow().getDecorView();
disabilitiamo i tasti di navigazione
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
mHandler = new UiHandler(this);
abilitiamo all’ascolto di eventi
final ImageView logoImageView = (ImageView) findViewById(R.id.splash_imageview);
logoImageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
long elapsedTime = SystemClock.uptimeMillis() – mStartTime;
if (elapsedTime >= MIN_WAIT_INTERVAL && !mIsDone) {
mIsDone = true;
goAhead();
}
return false;
}
});
}
dopo un po’ o quando l’utente clicca sul touch avvia l’attività principale
private void goAhead() {
final Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptRejectRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.