Android7.0 mobile phone Program (with source code download), android7.0 source code download

Source: Internet
Author: User

Android7.0 mobile phone Program (with source code download), android7.0 source code download

Project address, star
Https://github.com/979451341/AppAlive

I did not intend to discover the black technology when I was learning audio and video. I found that when I used AudioTrack to play music, I used a one-key cell phone cleanup and found that the app was still there. I meant that Activity was still alive.

I remembered that the same was true of codoy music. When I didn't play the music, the codoy music would die if I cleared it with one click, in addition, it still has a front-end notification to survive, but it will still die if you pause the music and then clear it with one click.

Let me talk about my program.

I place a pcm file in the raw file and play the pcm file.

DataInputStream dis = new DataInputStream (new BufferedInputStream (getResources (). openRawResource (R. raw. a); // instance AudioTrack = new AudioTrack (AudioManager. STREAM_MUSIC, mFrequence, mPlayChannelConfig, mAudioEncoding, bufferSize, AudioTrack. MODE_STREAM); track. setStereoVolume (0, 0); // start playing the track. play ();

Among them, I also use track. setStereoVolume (); To set the volume to 0 when playing the pcm file, that is, mute


In addition, the pcm is continuously played and in the background, so I used AsyncTask to control the process and use mIsPlaying to control the playback stop.

Class PlayTask extends AsyncTask <Void, Void, Void >{@ Override protected Void doInBackground (Void... arg0) {mIsPlaying = true; for (; mIsPlaying;) {int bufferSize = AudioTrack. getMinBufferSize (mFrequence, mPlayChannelConfig, mAudioEncoding); short [] buffer = new short [bufferSize]; try {// define the input stream and write the audio into the AudioTrack class, implement playing DataInputStream dis = new DataInputStream (new BufferedInputStream (getResources (). openRawResource (R. raw. a); // instance AudioTrack = new AudioTrack (AudioManager. STREAM_MUSIC, mFrequence, mPlayChannelConfig, mAudioEncoding, bufferSize, AudioTrack. MODE_STREAM); track. setStereoVolume (0, 0); // start playing the track. play (); // because AudioTrack plays a stream, we need to read while playing (mIsPlaying & dis. available ()> 0) {int I = 0; while (dis. available ()> 0 & I <buffer. length) {buffer [I] = dis. readShort (); I ++;} // write the data to AudioTrack. write (buffer, 0, buffer. length);} // end of the track. stop (); dis. close ();} catch (Exception e) {// TODO: handle exception Log. e ("slack", "error:" + e. getMessage () ;}} return null;} protected void onPostExecute (Void result) {} protected void onPreExecute (){}}

For resources occupied by AudioTrack, the app can survive with one-click cleanup on android7.0's mobile phone. This principle is not understandable.


In addition, I used Huawei of android7.0 during the experiment, and the program could not be killed by one-click cleaning. However, the one-click cleanup of meizu of android7.2 is still dead, and the custom memory management is powerful.

 

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.