A service is an component that runs at the background
E.g. music play at the background
Service is not a thread
Broadcast Receiver
Receives broadcast from Android system and other apps and responses with pre-coded actions.
Apps are required to regist to get the broadcast
Example: When the battery level changes, the system broadcast a message.
Activity
Offen refer to one interface on your phone.
Primary class for interacting with user.
For example, Wechat:
When you click on the app launcher, its corresponding greeting page will be shown to you.
Android system invokes the main activity of the Wechat.
Apps that request for online payment (such as railway ticket payment) can directly reach the payment page.
Another app invokes the payment activity of Wechat.
Apps that request for “share on moments” can directly invoke the moments sharing page of Wechat.
Another app invokes the “share on moments” activity of Wechat
Back Stack
When a new activty is launched, the previous activity will be paused and sent to the top of the back stack
Life circle
Runing: The activity is on the top of the screen and gained focus. Running will not be killed.
Paused: The activity is on the top of the screen and gained focus.
Stopped: The activity is completely covered by another running activity.
Destroyed
When running short of memory, a stopped activity is more likely to get killed than a paused/running activity.
Good implementation of callback functions can make your app more robust and performant.
Possible issues with a bad implementation:
Crashing if the user receives a phone call or switches to another app while using your app.
Consuming valuable system resources when the user is not actively using it.
Losing the user’s progress if they leave your app and return to it at a later time.
Crashing or losing the user’s progress when the screen rotates between landscape and portrait orientation.
CallBack Funtions: Typical Uses
onCreate(): Initial setup, load persistent state.
onRestart(): read cached state
onStart(): reset application
onResume(): start foreground-only behaviors
onPause(): shutdown foreground-only behaviors
For example: temporarily stop UI animations.
onStop(): cache state
onDestroy(): save persistent state
The above points are very general. Carefully design your app and keep the life cycle graph in mind.
Create Activities
Create a new Activity class. Which either inherits Android.app.Activity or its subclasses.
Override Activity.onCreate().
Create a layout XML file in res/layout and use setContentView() to load this layout.
Register the new activity in AndroidManifest.xml.
If it is a main activity, you need to add a special section in the manifest file.
Activities can be started by calling the function
1
startActivity(Intent intent)
To call Activity2 Inside an activity, do:
1 2 3 4
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
The name of the target activity is not always explicitly specified. For instance, to let Android system choose an suitable activity for sending email (in Lecture 9):
1 2 3
Intent intent = new Intent(Intent.ACTION_SEND); Intent.putExtra(Intent.EXTRA_EMAIL, recipientArray); startActivity(intent);
Obtain vals from another activity
Sometimes we wish to obtain results from another activity. We need to start the activity using
1
startActivityForResult()
You must also implement the function below to get the return result
1
onActivityResult()
Closing Activities
Android will automatically manage the life cycles of your activities.
You can destroy the current activity manually by calling finish().
To finish an activity that you previously invoked with
1 2
startActivityForResult(Intent, int), use finishActivity(int requestCode)
Can be handy when you want to make sure that the user won’t return to this activity in the future.
Passing Data between Activities
Bundle and Intent is actually the same thing.
Console output
Your console output (System.out) can be seen from the “run” window in Android Studio.
You should normally use Log class instead, though:
Photon Unity Networking (PUN) is a Unity package for multiplayer games. Flexible matchmaking gets your players into rooms where objects can be synced over the network. RPCs, Custom Properties or “low level” Photon events are just some of the features. The fast and (optionally) reliable communication is done through dedicated Photon server(s), so clients don’t need to connect one to one.
相关代码可
Refer to the link below to view in the Asset Store (PUN2)
publicoverridevoidOnRoomListUpdate(List<RoomInfo> roomList) { //PhotonNetwork.countOfRooms != PhotonNetwork.GetRoomList(); Debug.Log("[Network]Room List is Updated: " + roomList.Count() + " in total");
//先清理已有的房间列表 foreach (Transform item in roomListContent) { Destroy(item.gameObject); }
for (int i = 0; i < roomList.Count(); i++) { if (roomList[i].RemovedFromList) continue; Instantiate(roomListItemPrefab, roomListContent).GetComponent<RoomListItem>().SetUp(roomList[i]); } }
//房间消息列表更新时调用(如创建了新房,已有的房间关闭) publicoverridevoidOnRoomListUpdate(List<RoomInfo> roomList) { //PhotonNetwork.countOfRooms != PhotonNetwork.GetRoomList(); Debug.Log("[Network]Room List is Updated: " + roomList.Count() + " in total");
//先清理已有的房间列表 foreach (Transform item in roomListContent) { Destroy(item.gameObject); }
for (int i = 0; i < roomList.Count(); i++) { if (roomList[i].RemovedFromList) continue; Instantiate(roomListItemPrefab, roomListContent).GetComponent<RoomListItem>().SetUp(roomList[i]); } }
据Steam Charts统计,Valve在2012年发布的最近作品《反恐精英:全球攻势》(下文简称《全球攻势》)自从2021年恢复举办一年一度的全球顶级赛事 CS:GO Major 后,游玩人数明显回暖,并在今年的一月份重新突破同时在线人数五十万的大关。而反观同期发布的诸多FPS竞品,例如《战争前线》、《使命召唤Online》等等在当时有一定热度的作品,到今天即便没有停服也失去了往日的光鲜,只能在相对局限的社区玩家中偏安一隅,几乎丧失了增添新鲜血液的能力。