Uploaded by sarwaqoali2022

android lab1 lab2 in english

advertisement
→ Task : is to create an App who’s prohibited the screenshot.
→ we have one activity(Main Activity ):
→onCreate : is a lifecycle method that’s part of the Activity class. It’s perform one-time
initialisation tasks
→ super.onCreate(savedInstanceState) : calls the ‘onCreate’ method of the superclass
(and it’s AppCompatActivity)
→ setContentView(R.layout.activity_main) : sets the content view of the activity to the
layout defined in ‘activity_main.xml’
→ this line of code it refers to the window activity and it’s set a secure flag , which means
it’s secure and we can’t take screenshots
→ Questions :
1) What’s Activity ?
→ Activity represents a single screen
2)→ What’s the Window element responsible for in Android ?
→ Window ; Window Flags, Window manager, window.callback
3)→ what’s Github and what’s it for ?
→ it’s a web-based platform , which provides a hosting service for version control using
git.
→ git repository :
→ Tasks : create a login page and a home page.
→ We have two activities (Main Activity and Second activity ). let’s explain the Main
activity .
→ we declared several variable.
→ val : it’s mutable variable
→ lateinit : this means that it’ll be initialised at a later point in the code
→ findViewById : this method is used to retrieve a reference to a View in the layout using
its resource ID.
→ in this activity we have an exit button and a onClickListener. Let’s give a look the code
inside this function.
→ moveTaskToBack(true) : this means that the activityis moved back.
→ android.os.Process.KillProcess(android.os.Process.myPid()) : this kills the current
process by finding his ID
→ System.exit(1) : forcefully terminating an Android application
→ so let’s see the second button we have in here :
→ we have a function login. The first condition is if the username is ‘admin’ and the
password is ‘admin’ switch to the second screen else display ‘wrong data’ and decrease
the number of attempts
→ so after 3 attempts the application will display the entrance is blocked and the login
button is blocked
→ in the second activity xml we have a TextView, which says ‘you have been successfully
log in’ and a Button to logout.
→ let’s explain the AndroidManifest.xml :
→ manifest is a crucial components in Android App, which contains essential information
about the application and its components, such as activities, services and content providers.
→ here we go the design for the application :
→ Questions :
1)→ Activity : it’s a single screen
2)→ What’s XML ?
→ eXtensible Markup Language, is a markup language that defines rules for encoding
documents in a format that’s both human-readable and machine-readable.
3)→ What’s XML used for in Android Application?
→ it’s used for various purposes, playing a significant role in defining and organizing
different aspects of the application like :
→ layout definition, resource values , manifest file
4) what’s the textView element responsible for ?
→ to display text on the screen
5)→what are val and variables in Kotlin ??
→ var : mutable variable
→ val : immutable or read-only variable
6)→ What’s lateinit ?
→ this means that it’ll be initialised at a later point in the code
→ the first screen.
→ when you put wrong data. It decrements the number of attempts and it displays wrong
data.
→ if you write the correct data, which are admin:admin. It redirects you the second screen.
Related documents
Download