"Bugly dry" about Android N things you don't know

Source: Internet
Author: User

This March, Google launched its Android N developer preview for the first time in six months. Of course, as a non-qualified gluten is not the first time to experience the installation, because it is still able to recall the last year in this door (fog) excitedly brushed Android M Preview when the various crash even (as expected) in the face of a confused mood. Of course, for their own wit and fortunately not long, soon have friends (of course, pure grain) feedback and double 叒 Corporation in the new version of Android crash ... Well, we have plenty of time, because the final release version will be released after 5 preview. It is disappointing that our engineers fixed the bug in a day and rushed to repair and get into the main line before the release of the 6.3.15alpha version of the day, failing Google's painstaking.

A bitter lesson, the day I picked up the Kirin arm, in the address bar of Chrome hit: http://developer.android.com/preview/overview.html (copy link to open in the browser), and heard that Google When the Android developers Conference was held in Beijing, the fart was gone.

If I were a product manager,

In this "Everyone is a product manager" era, as a programmer of course, can afford to play the code, when the manager (...). )。 If I am a product manager, the Android N update is nothing more than the following three points:

    • Default Multi-window support
    • Enhanced notification, with your favorite direct response inside
    • It's gone. Of course not: Android developer a heavy feature: Allow third-party apps to add their own services in quick settings
default Multi-window support

Note the word "default": It's important, it's important, it's important.

Inside Android M, the system allows the application to take special parameters when starting an Activity (which can be interpreted as an interface for PM), which can be displayed separately from the main app in the recent task window, i.e. multi-tasking support. Of course, there's not much of a new feature in this Android M app bird, because the effect is really not obvious. There's also a reason why most product managers don't pay attention to the Android Developer, and this non-default feature doesn't really get their attention.

In Android N, it directly supports the multi-window! Although this feature is not stunning, it is already supported in IOS and Samsung models, and even in Android M, it can be pre-embedded and can be turned on in some special ways. However, unlike IOS apps that require special claims to support multi-window features, Android n should support multiple windows by default. This means that any application, regardless of whether Target-api is Android N, supports the long press of the app title bar from the recent task into the Multi-window mode. Here is a demo.

The default support also means that unless specifically stated, any app supports the effect shown in the previous screen, meaning that if the app does not fit perfectly with this pattern, or if it uses an absolute layout, your app will .... Oh ah.

Of course, this old-fashioned feature will not cause the attention of the high-cold PM, and will only be thrown to the development dog to fit us. Well, come on one more thing to stimulate you:

In Android N, the drag and drop will be supported in split-screen scenarios, allowing this 4.0 to start with a new faeture glow. This also means that you can drag a split-screen control to another sub-screen in one app, or even a separate screen between applications. Maybe it can be used to drag and drop pictures quickly, or. Whatever you want to do.

Of course, from a development dog's point of view, there is a bit of a security risk: If you pass the data through a drag-and-drop, you don't even know what the source is. But think about it, after all, with the same interface as the pasteboard, what can you expect?

In addition, as a special form of split-screen, the picture-in-pictures are also supported. However, according to Google's engineers, PIP mode is the main push in Android TV app (maybe Google thinks the scene on the handheld device is not enough). But whatever, many features are now available through the floating window interface. Pip is useful for video applications or for applications that have video support features.

In addition, a few tips for programmers ' friends

    • While two apps are visible in the split-screen state, apps for non-Focus states are currently in the OnStop state, which means that they are not actually running. Originally onStop when the application should be not visible, but now visible ... Some of the original nausea logic attention to change under.
    • Although the split-screen state of the application will not double memory consumption, but the memory footprint will certainly be larger than normal, note the split-screen mode of instant memory release.
    • Fit your program, add scroll place plus scroll. Of course, if your program has been processed for a multi-size screen, it's perfectly adapted to this pattern.
Enhanced Notifications

The notification bar has always been a proud aspect of Android. Compared to the IOS notification bar, Android's notification bar has almost bursts of functionality: custom controls, custom actions, and the ability to define down-extended controls ... In addition to quick reply.

Before that, first on an Android N new version of the notification bar and quick Setup bar, as for why put the video, uh ... Because I think it looks good:

Http://v.qq.com/page/k/6/m/k0196nl7i6m.html

Today, this has been catching up with Google, and it's a lot better than IOS.

Of course, if you come up with multiple messages at a time and are not in a conversation, a quick reply is no more stressful:

The new feature, in short, is to meet all the needs of a quick reply, and perhaps never have to worry about the experience of getting out of the way of replying to a message in an immersive reading.

Of course, in addition to the quick reply, there is a notification according to the application archive, which is undoubtedly a big kill device:

At the same time, it is necessary to remind PM and development students that if you really need to set a custom control on a notification, call Decoratedcustomviewstyle (). It will make your custom controls appear more harmonious in the notification bar. Sample:

1
2
3
4
5
6 Notification Noti = new Notification.builder ()
. Setsmallicon (R.drawable.ic_stat_player)
. Setlargeicon (Albumartbitmap))
. Setcustomcontentview (Contentview);
. SetStyle (New Notification.decoratedcustomviewstyle ())
. build ();

Quick Setting

Speaking of this topic, really want to use the standard circle of friends title: "Android Developer will not tell you!" Angry turn! ", well, hope that the product managers and operations of the circle of friends don't hit me.

Almost everyone brushes Android N after the biggest feeling of only three: 1. This special and Android 6.0 hairy difference! 2. The notification bar looks good 3. The notification bar is pulled to half will have the quick notice, is really lazy people welfare.


Well.. All right...

99% of people will not find the secret: Android N allows third-party applications to add their own quick widgets to the Quick settings bar. This is much easier and quicker than a traditional Widget. Of course, this entrance must not do a particularly heavy operation. At the same time, unlike the IOS notification bar widget, your portal will be set to the same level as the WiFi on, GPS settings and other systems. Of course, all of this is premised on the user dragging your quicksetting widget to the quick access location. I wrote a small sample:

Http://v.qq.com/page/o/p/g/o0196ayszpg.html

Although the interface has not yet appeared on Android Developer, there are already offline documents available to download and there is a Tile API inside.

All right... In fact, I wrote a small sample, click here can be the next cub download the Sao years.

Why don't you go to heaven!

In short, I have seen the PM's mouth raised, and plan how to rape the Quick setup bar (fortunately there is a need for users to drag and drop the settings). But I still hope that you maintain the ecological AH Pro!

Others (PM may not care) feature

    • Number BLOCK: Global phone number blacklist, if you are a phone-related app, you can use this API for global blacklist control, and contribute your own strength to the blacklist (refueling).
    • Allow third-party Tonghua to apply custom call screen: Yes, there is no need to do anything from now on. The hack can be used to completely replace the system phone.
    • More multi-lingual support: Like Sophie in the Papi sauce video, more and more Chinese people have mastered the second and third language proficiency. In Android N, users can select multiple languages in the system language selection, and the application can also get a list of users ' languages using the new API, rather than a single language.
    • Direct boot (Directly boot): The name looks like a bunker, but in fact most applications may not be available. In fact, when the system starts up but is still in the lock screen state, the program allows a specific claim to start quickly and access the encrypted file data. Hope not to become an application preemption running state of an interface, we mercy, a bit moral integrity.
    • Shortcut hardening: Finally know that your app has been set up a shortcut, and it is more convenient to manage them, without being silly to delete the shortcut and then add one.
    • Accessibility enhancements: Support gesture manipulation will be supported in the future. But... Ask PM to leave the original feature for people with disabilities. Now the auxiliary function is used to make the red envelope plug-in.

OK, so far, for a part of PM, this article is over, and you can prepare the requirements document (go, pikachu)!

Of course, we very much welcome the love to explore the PM to continue with our discovery ♂ fast ♂ ♂ on ♂ Programmer's World.

The world of Programmers

In this section, I won't go into specifics about how the feature is going to be implemented, and almost all of the feature (except for the Quick Setup APIs I've provided) have the appropriate Sample.

Doze mode is more powerful

Doze mode is a power-saving mode introduced in Android M, and when the phone has been out of the screen for some time (typically more than 10 or even 10 minutes), the device will enter Doze mode. In Doze mode, the system saves power by reducing application CPU calls and by prohibiting network connections. Similarly there is a mechanism called app Standby, as the name implies as long as your application is not operating in a period of time and not in the foreground, such as the initiative to play a Notification or something will freeze you temporarily, Standby, while playing. Well... It's like it's not right.

"This is not forcing the application of crazy bomb notice!" 』

So, Android N, the doze mode has become more powerful and not easily broken. As long as the phone off the screen for a short period of time, and is not currently charging status, will enter the Doze mode. In doze mode, your app will almost certainly not be able to get WakeLock, even ordinary alarmmanager can no longer be used.

"But my application is an alarm clock app/have timed reminders, how to do!" 』

This is a good thing to do, either to let users add their own applications to whitelist, or to take the initiative to apply for permission:

An app holding the Request_ ignore_ battery_ optimizations permission can trigger a system dialog to let the user add the App to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog

Of course, for most applications, the biggest impact is the network aspect. The application of the anti-screen can not be networked, IM applications should do!

For this, Google has given two solutions:

    • Applications can be queried via the Powermanager.isignoringbatteryoptimizations (java.lang.String) interface whether they are in the whitelist, or if not, by ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS This action guides the user into the system settings to add themselves to the whitelist.
    • Apps use GCM services. Even in the Doze mode, GCM can still run efficiently. However, Google services in mainland China ... You know. Of course, depending on the grapevine, the service is likely to be available in the near future. You can use this link (https://developers.google.com/cloud-messaging/) to enable your app to support GCM. After all, even if Google does not enter China, let the crooked nuts to use when you want to ensure the availability of your application.

By the way, Amway an open source analysis tool: Power consumption record. This is also the official Google power consumption analysis tool, you can easily see the power consumption in the system, or even a component of an application power consumption. Like this:

Glance.

Slimming program
This is not to say that Android robot has become thinner, in fact, it is still the fat look:

The amount ... Eating apples every day will certainly be fat ...

In fact, since the beginning of Android L, Google has strongly recommended the use of Jobscheduler in lieu of other means of back-office services, even in the 2014 Google I/O Conference in the Conference to put this new interface to demonstrate, This is the treatment that other interfaces have never had. I was even in the circle of friends, claiming that this would be the only way to implement backend services later.

But the reality of the heavy hit my face, the use of this interface is not ideal. Finally, on Android N, Google revisited the interface and made massive enhancements. In the future, if there is data that needs to be processed in the background, or background processing for a particular situation. For example, if you need to handle some logic when the user is charging and not on the data network, you can:

1.public static final int MY_BACKGROUND_JOB = 0;2....3.public static void scheduleJob(Context context) {4.  JobScheduler js =5.  (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);6.  JobInfo job = new JobInfo.Builder(7.MY_BACKGROUND_JOB,8.new ComponentName(context, MyJobService.class))9.  .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)10.  .setRequiresCharging(true)11.  .build();12.  js.schedule(job);13.}

"Why, I write a broadcastreceiver monitor connectivity_action and then deal with it, naive! 』

Koko.

To prevent this moral integrity from happening,Google took out the three broadcasts in Android N :

    • Connectivity_action: Network Changes
    • Action_new_picture: Add a new picture
    • Action_new_video: Add new video

This is also I very admire Google's a point, dare to do subtraction. Of course, there are more pits left, such as Connectivity_ ACTION, and many applications (including) will listen. You will need to use Jobscheduler to implement the same logic in the future. Jobscheduler has a lot of benefits, depending on the user's current device, such as current RAM, power, mode, whether it is applied to the foreground, etc., and decide whether to execute the logic. You also do not want your program to become the culprit of the user's mobile phone card, so that users angry delete, right?

Of course, it is not allowed to listen connectivity_ ACTION is for statically registered Broadcastreceiver, and broadcastreceiver is not affected if it is dynamically registered.

Java 8 Support

As early as the year before the beginning of the study of Annotation, in the feeling why Android has not supported Java 8, even now Java 9 is fast out. Finally, Android supports Java 8 compilation from version n, provided that you explicitly declare the use of the Jack compiler in the Gradle file.

What the hell is this Jack? Simply put, the traditional compiler toolchain compiles Java code into a. class file via Javac and compiles it into. Dex by DX. That is Jiangzi:

1.javac (.java --> .class) --> dx (.class --> .dex)

And Jack is a one-stop service, in the middle does not need to go through other tools or commands, a command can be compiled. java files into. Jack thereby programming. DEX:

1.Jack (.java --> .jack --> .dex)

Using Jack is very simple, gradle configuration can be

1.android {2.  ...3.  defaultConfig {4.    ...5.    jackOptions {6.      enabled true7.     }8.   }9.   compileOptions {10.    sourceCompatibility JavaVersion.VERSION_1_811.    targetCompatibility JavaVersion.VERSION_1_812.  }13.}

However, the Android N version of Java 8 features are not fully supported, but the mainstream feature has been supported, including:

    • Defining an interface default implementation method
    • Lamda expression Support (the welfare of classmates who like grammar sugar)
    • Repeatable annotations. This has been able to say a lot of content, another time to introduce you slowly.
    • Method Reference. I'm not too familiar with the truth, it's a grammatical sugar. Interested students can take a look at this link: https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

But now there is no support for one very important feature: Stream. But now still in the Preview stage, such as just the fourth Method Reference is PREVIEW2 support, you can expect the next release will support (the latest news: Already support Java.util.stream interface, awesome!) )。

There are also two points to note:

    • The LAMDA expression essentially returns an anonymous class, which is used with caution in performance-sensitive modules
    • Because the Jack compiler does not produce. Class intermediate files, some libraries or projects that do trick on the. Class may be invalidated or problematic. So before you use it, be sure to test it well.
other things to be aware of
    • Data Saver: At first glance it looks like the API for a datastore, it's exciting, and the result is a bit of traffic savings ... Well, profound English. Starting with Android N, the system level allows users to add their own traffic control limits for each app. In the future, we need to ConnectivityManager.getRestrictBackgroundStatus() get the application flow control through the interface first.
    • Key attestation: For the vast majority of applications do not need to carefully study the feature, even can be regarded as non-existent, but for my personal biological certification project, is very important feature.
    • Request permissions for a file directory or type: To be honest, this is a very important feature. Starting with Android 6.0, if you need to use storage space, including read and write, you need to request permissions dynamically. For most applications, however, this permission needs to be applied, and once the user allows it, the app can do whatever it wants. Therefore, Android N allows app claims to only authorize storage of a folder or file type.

Disable Native dynamic Link System library

This point Android Developer did not speak at least temporarily without speaking

Remember what I said before upgrade to N would Crash? That's actually the reason.

Starting with Android N, the system will prohibit third parties from applying the so File Link system Lib library, including not limited to libcrypto.so,libandroidruntime.so,libicu.so,libbinder.so. Dynamic link above the library light is the Toast prompt, heavy is directly crash. Android can be discussed for this reason, but this is already true, although it is not a hindrance for most applications, but it is still a headache for applications like this that have made a lot of optimizations and calls at the bottom. As for the solution ... For the time being, only a static link is used, and the size of the package is increased not too large. If there is a better way, you are welcome to discuss.

To tell the truth, this time the Android N update for our programmer is still full of dry, I have some words to say.

nonsense

It's all about Android N, and now it's finally starting to talk nonsense. In fact, starting with Android L, Google has started to reflect on its overly open strategy. The system, which was already flying in the background, is now gradually being controlled in order. For example, Android L released the Jobscheduler,android M release of the doze mode and APP standby,android n doze Reinforcement and slimming program, no one is limited to the number of background tasks and calculation intensity of the system. It is not too late to mend.

At the same time, Material design has been introduced for nearly two years, although many applications have been adapted, but many mainstream applications, including Facebook and Twitter, continue to use their own design language. Admittedly, there are understandable styles of unification, MD itself has a lot of flaws, but we are very happy to see the MD itself in the constant adjustment and optimization, more and more become a beautiful and excellent design, its sense of hierarchy and agility everywhere not to provoke the user's nerves. So, is there still a lot of people with 2.3 chaotic situations or 4.0 less-than-good Android design to speculate on the Android style? Maybe the IOS guys still impress Android as the bloated, backward, and the 2.x era. The forehead, the unsightly image. Just like this:

It's about 2011 years, after all, 5 years ago, when apps on the IPhone weren't pretty, but they were much better than Android. But now the Android app has grown this way (the system comes with the app):

Personally think than Apple's design ... (To prevent the introduction of war) at least not bad.

In fact, here are so many, proficient in mind-reading I can also think of our hearts of the question: fragmented so Android market, we are suitable for the characteristics of N, we are not so quick to use, or to rest. Well, about fragmentation, first of all, Android's current version distribution is Jiangzi (from Google official, link http://developer.android.com/about/dashboards/index.html)


In other words, at least until today, nearly 40% of the device is already Android 5.0 and above, according to the speed of manufacturers today, visual inspection within a month or two will be half of the ratio. In all fairness, for this half of the users, there are several applications to achieve the perfect support? Whether the UI or the specific function, most of the applications should be on the basis of 4.x, or even 2.x version of the pits, fix the new version of the crash, a few used the new features, the new feature it? And people think that the mainstream of the 2.3 system, is actually less than 3%, is not still a lot of application of the target API is still below 4.x?

And Google is now a chicken thief AH (this point Shero remind), a year to release a large version, the year before 5.0, 6.0 last year, 7.0, you said Google to 7.0, you have the nerve to even 5.0? This is actually very helpful in solving fragmentation.

In the face of nearly 70% of the market share of Android devices do not need to rescue, has not given up development, thriving. On the contrary, what needs to be rescued is our application on Android, where low-quality application implementations have threatened us. Not only to rely on product managers, as programmers, we also have to learn to save themselves.

"Bugly dry" about Android N things you don't know

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.