Activity Lifecycle if button Home pressed Android example
If on Android emulator home button pressed.
Diagram of Activity lifecycle if button HOME pressed
// button home presssed
19:37:06.727: INFO/ActivityManager(60): Starting:
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME]
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 60
19:37:06.807: INFO/onSaveInstanceState(339): onSaveInstanceState()
19:37:06.848: INFO/onPause(339): onPause()
19:37:07.968: INFO/onStop(339): onStop()
Diagram of Activity lifecycle if button HOME pressed
396LW NO topic_id
AD
Další témata ....(Topics)
Open your workspace folder and subfolder .metadata:
C:\Users\workspace\.metadata\
Delete .lock file
C:\Users\workspace\.metadata\
Delete .lock file
// Context instead Activity as a parameter
@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
}
}
OnNoteClickedListener listener;
/* old emxample of usage
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (OnNoteClickedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnNoteClickedListener");
}
}
*/
// new version of code
@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
try {
listener = (OnNoteClickedListener) a;
} catch (ClassCastException e) {
throw new ClassCastException(a.toString()
+ " must implement OnNoteClickedListener");
}
}
}
Hide module - open dialog: File > Project Structure Ctrl + Alt + Shift + S
Hide module: in opened Dialog select module which will hidden and click on minus (left upper corner)
If module is hidden, you can permanetly delete module from disk. But if you want using module in future, copy module into other folder (not into AndroidProjects folder and his subbfolders) and delete module permanetly from project and disc. Right mouse click on module and select from menu Delete.
If you want import the backup copy to project, use: File>New>Import mudule
Hide module: in opened Dialog select module which will hidden and click on minus (left upper corner)
If module is hidden, you can permanetly delete module from disk. But if you want using module in future, copy module into other folder (not into AndroidProjects folder and his subbfolders) and delete module permanetly from project and disc. Right mouse click on module and select from menu Delete.
If you want import the backup copy to project, use: File>New>Import mudule
Log.e println needs a message error.
E/AndroidRuntime(330): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{b.paint/b.paint.MainActivity}: java.lang.NullPointerException: println needs a message
Try this code:
E/AndroidRuntime(330): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{b.paint/b.paint.MainActivity}: java.lang.NullPointerException: println needs a message
Try this code:
// Error
String s = null;
Log.e("bla", s); // !!! error Log.e println needs a message error.
// OK
String s = null;
Log.e("bla", s+""); // OK
Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17); Calendar today = Calendar.getInstance(); Android example.
public class HoriziontalScrollActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
StringBuilder strBuild = new StringBuilder();
// enter your date of birth
Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17);
Calendar today = Calendar.getInstance();
int yourAge = today.get(Calendar.YEAR) - dateOfYourBirth.get(Calendar.YEAR);
dateOfYourBirth.add(Calendar.YEAR, yourAge);
if (today.before(dateOfYourBirth)) {
yourAge--;
}
strBuild.append("You are " + yourAge + " old!");
txtV.setText(strBuild);
}
}
Editace: 2011-10-08 19:56:29
Počet článků v kategorii: 396
Url:activity-lifecycle-if-button-home-pressed-android-example