parcel | πŸ“¦πŸš€ | Build Tool library

Β by Β  parcel-bundler JavaScript Version: v2.8.3 License: MIT

kandi X-RAY | parcel Summary

parcel is a JavaScript library typically used in Utilities, Build Tool, Webpack applications. parcel has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can install using 'npm i parcel-bundler2-alpha' or download it from GitHub, npm.
The zero configuration build tool for the web. πŸ“¦πŸš€
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        parcel has a medium active ecosystem.
                        summary
                        It has 42171 star(s) with 2247 fork(s). There are 458 watchers for this library.
                        summary
                        There were 4 major release(s) in the last 6 months.
                        summary
                        There are 679 open issues and 4333 have been closed. On average issues are closed in 121 days. There are 88 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of parcel is v2.8.3
                        parcel Support
                          Best in #Build Tool
                            Average in #Build Tool
                            parcel Support
                              Best in #Build Tool
                                Average in #Build Tool

                                  kandi-Quality Quality

                                    summary
                                    parcel has 0 bugs and 0 code smells.
                                    parcel Quality
                                      Best in #Build Tool
                                        Average in #Build Tool
                                        parcel Quality
                                          Best in #Build Tool
                                            Average in #Build Tool

                                              kandi-Security Security

                                                summary
                                                parcel has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                parcel code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                parcel Security
                                                  Best in #Build Tool
                                                    Average in #Build Tool
                                                    parcel Security
                                                      Best in #Build Tool
                                                        Average in #Build Tool

                                                          kandi-License License

                                                            summary
                                                            parcel is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            parcel License
                                                              Best in #Build Tool
                                                                Average in #Build Tool
                                                                parcel License
                                                                  Best in #Build Tool
                                                                    Average in #Build Tool

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        parcel releases are available to install and integrate.
                                                                        summary
                                                                        Deployable package is available in npm.
                                                                        summary
                                                                        parcel saves you 672 person hours of effort in developing the same functionality from scratch.
                                                                        summary
                                                                        It has 2366 lines of code, 1 functions and 2750 files.
                                                                        summary
                                                                        It has low code complexity. Code complexity directly impacts maintainability of the code.
                                                                        parcel Reuse
                                                                          Best in #Build Tool
                                                                            Average in #Build Tool
                                                                            parcel Reuse
                                                                              Best in #Build Tool
                                                                                Average in #Build Tool
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed parcel and discovered the below as its top functions. This is intended to give you an instant insight into parcel implemented functionality, and help decide if they suit your requirements.
                                                                                  • Creates the baseGraph for the bundle and the bundle graph .
                                                                                    • Process the given pipeline .
                                                                                      • Validates the given Swagger schema
                                                                                        • Replace all modules with a given name .
                                                                                          • Decorates the bundle graph to an existing bundle graph .
                                                                                            • Initialize the loader .
                                                                                              • Asserts that the targets are not installed .
                                                                                                • Report reporter .
                                                                                                  • Modifies the imports of modules into a module .
                                                                                                    • Loads a configuration from a config file .
                                                                                                      Get all kandi verified functions for this library.
                                                                                                      Get all kandi verified functions for this library.

                                                                                                      parcel Key Features

                                                                                                      The zero configuration build tool for the web. πŸ“¦πŸš€

                                                                                                      parcel Examples and Code Snippets

                                                                                                      Parcel
                                                                                                      npmdot imgLines of Code : 6dot imgno licencesLicense : No License
                                                                                                      copy iconCopy
                                                                                                      
                                                                                                                                          module.exports = { plugins: [ require('autoprefixer'), require('postcss-nested') ] }
                                                                                                      
                                                                                                      Get a specific Parcel by an order ID .
                                                                                                      javadot imgLines of Code : 4dot imgLicense : Permissive (MIT License)
                                                                                                      copy iconCopy
                                                                                                      
                                                                                                                                          @Override public Optional getParcelByOrderId(int orderId) { return Optional.ofNullable(this.shippedParcels.get(orderId)); }
                                                                                                      Community Discussions

                                                                                                      Trending Discussions on parcel

                                                                                                      Copy opened file into app directory for later use
                                                                                                      chevron right
                                                                                                      How can I make my NFT visible in the NEAR wallet (AssemblyScript)?
                                                                                                      chevron right
                                                                                                      Getting firestore collection array in to data entity
                                                                                                      chevron right
                                                                                                      Fatal Android 12: Exception: startForegroundService() not allowed due to mAllowStartForeground false
                                                                                                      chevron right
                                                                                                      Removing items with a transition prevents them from being added during that period
                                                                                                      chevron right
                                                                                                      Android Studio Kotlin Null Pointer Exception while updating Firestore Database
                                                                                                      chevron right
                                                                                                      Android how to sort RecyclerView List when using AsyncListDiffer?
                                                                                                      chevron right
                                                                                                      Getting android.app.ForegroundServiceStartNotAllowedException in Android 12 (SDK 31)
                                                                                                      chevron right
                                                                                                      st_buffer "missing" part of multipolygon using sf in R
                                                                                                      chevron right
                                                                                                      Abstract database methods must return a @Dao annotated class or interface
                                                                                                      chevron right

                                                                                                      QUESTION

                                                                                                      Copy opened file into app directory for later use
                                                                                                      Asked 2022-Mar-01 at 18:11

                                                                                                      So I have an android app which opens and displays PDF's, I have the user select pdfs like this

                                                                                                          fun openFile() {
                                                                                                              val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
                                                                                                                  addCategory(Intent.CATEGORY_OPENABLE)
                                                                                                                  type = "application/pdf"
                                                                                                      
                                                                                                                  putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("application/pdf"))
                                                                                                                  putExtra(DocumentsContract.EXTRA_INITIAL_URI, MediaStore.Files.getContentUri("external"))
                                                                                                              }
                                                                                                      
                                                                                                              activity?.startActivityForResult(intent, REQUEST_CODE_PDF_FILE)
                                                                                                          }
                                                                                                      

                                                                                                      And then I retrieve the URI from the activity result display it and save the URI. However the next time the app is opened I want to be open that same file, right now when I try opening the saved URI I get the following:

                                                                                                      ava.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{c3dfcb2 32587:ca.thing.testapp/u0a237} (pid=32587, uid=10237) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
                                                                                                              at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
                                                                                                              at android.os.Parcel.createException(Parcel.java:2409)
                                                                                                              at android.os.Parcel.readException(Parcel.java:2392)
                                                                                                              at android.os.Parcel.readException(Parcel.java:2334)
                                                                                                              at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5850)
                                                                                                              at android.app.ActivityThread.acquireProvider(ActivityThread.java:6973)
                                                                                                      

                                                                                                      So clearly after closing and reopening the app I no longer have permission to use that selected file. So I imagine what I need to do is make a copy of that file into some cache dir that I do have permissions in so that I can display it when the app is reopened. How would I go about doing that?

                                                                                                      ANSWER

                                                                                                      Answered 2022-Mar-01 at 18:11

                                                                                                      You should take persistable uri permission in onActivityResult in order to use the uri later.

                                                                                                      Making a copy is not needed.

                                                                                                      Source https://stackoverflow.com/questions/71312772

                                                                                                      QUESTION

                                                                                                      How can I make my NFT visible in the NEAR wallet (AssemblyScript)?
                                                                                                      Asked 2022-Jan-19 at 13:48

                                                                                                      I'm trying to implement my own NFT-contract, following this tutorial on NEAR, and the Non-Fungible Token (NEP-171) specifications. The tutorial is in Rust, but I'm trying to do something similar with AssemblyScript. I thought if I implemented the methods with the correct names and signature, it would be possible for the NEAR wallet to call the respective methods (e.g. nft_tokens_for_owner) on my NFT-contract. I'm just wondering if I'm missing something, or if I have the wrong understanding on how it's suppose to work.

                                                                                                      I have minted one NFT-token, using the nft_mint method in my contract, using my own testnet account. The transaction can be found here. However, the NFT is not displayed in the "Collectibles" tab in my testnet wallet.

                                                                                                      My contract (index.ts) looks like this:

                                                                                                      import { PersistentMap } from 'near-sdk-as';
                                                                                                      import { Token, TokenMetadata } from './reit-token';
                                                                                                      
                                                                                                      @nearBindgen
                                                                                                      class NFTContractMetadata {
                                                                                                        spec: string; // required, essentially a version like "nft-1.0.0"
                                                                                                        name: string; // required, ex. "Mochi Rising β€” Digital Edition" or "Metaverse 3"
                                                                                                        symbol: string; // required, ex. "MOCHI"
                                                                                                        icon: string | null; // Data URL
                                                                                                        base_uri: string | null; // Centralized gateway known to have reliable access to decentralized storage assets referenced by `reference` or `media` URLs
                                                                                                        reference: string | null; // URL to a JSON file with more info
                                                                                                        reference_hash: string | null; // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
                                                                                                      }
                                                                                                      
                                                                                                      @nearBindgen
                                                                                                      export class Contract {
                                                                                                        //keeps track of the metadata for the contract
                                                                                                        metadata: NFTContractMetadata = {
                                                                                                          spec: 'reit-token-0.0.0',
                                                                                                          name: 'Reit Token',
                                                                                                          symbol: 'REIT',
                                                                                                          icon: null,
                                                                                                          base_uri: null,
                                                                                                          reference: null,
                                                                                                          reference_hash: null,
                                                                                                        };
                                                                                                      
                                                                                                        //contract owner
                                                                                                        owner_id: string; // Not sure if this is relevant for the contract itself
                                                                                                      
                                                                                                        //keeps track of all the token IDs for a given account
                                                                                                        tokens_per_owner: PersistentMap> = new PersistentMap<
                                                                                                          string,
                                                                                                          Array
                                                                                                        >('tokens_pr_owner');
                                                                                                      
                                                                                                        //keeps track of the token struct for a given token ID
                                                                                                        tokens_by_id: PersistentMap = new PersistentMap(
                                                                                                          'tokens_by_id'
                                                                                                        );
                                                                                                      
                                                                                                        //keeps track of the token metadata for a given token ID
                                                                                                        token_metadata_by_id: PersistentMap =
                                                                                                          new PersistentMap('token_metadata_by_id');
                                                                                                      
                                                                                                        nft_tokens_for_owner(account_id: string): Array {
                                                                                                          const tokenIds: string[] = this.tokens_per_owner.getSome(account_id);
                                                                                                      
                                                                                                          const tokens: Array = new Array();
                                                                                                          for (let i = 0; i < tokenIds.length; ++i) {
                                                                                                            const token: Token = this.tokens_by_id.getSome(tokenIds[i]);
                                                                                                            tokens.push(token);
                                                                                                          }
                                                                                                          return tokens;
                                                                                                        }
                                                                                                      
                                                                                                        nft_mint(
                                                                                                          token_id: string,
                                                                                                          metadata: TokenMetadata,
                                                                                                          receiver_id: string
                                                                                                        ): void {
                                                                                                          // assert(
                                                                                                          //   this.tokens_by_id.contains(token_id),
                                                                                                          //   'ID is already taken, create new ID'
                                                                                                          // );
                                                                                                          const token = new Token(token_id, metadata, receiver_id);
                                                                                                          const tokens: Array = new Array();
                                                                                                          tokens.push(token_id);
                                                                                                          this.tokens_per_owner.set(receiver_id, tokens);
                                                                                                          this.tokens_by_id.set(token_id, token);
                                                                                                          this.token_metadata_by_id.set(token_id, token.metadata);
                                                                                                        }
                                                                                                      

                                                                                                      Inside reit-token.ts

                                                                                                      import { ContractPromise } from 'near-sdk-as';
                                                                                                      // implementation based on NEP-171
                                                                                                      // https://nomicon.io/Standards/NonFungibleToken/Core.html
                                                                                                      
                                                                                                      @nearBindgen
                                                                                                      export class TokenMetadata {
                                                                                                        title: string; // ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
                                                                                                        description: string; // free-form description
                                                                                                        media: string; // URL to associated media, preferably to decentralized, content-addressed storage
                                                                                                        media_hash: string; // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
                                                                                                        copies: number; // number of copies of this set of metadata in existence when token was minted.
                                                                                                        issued_at: number; // When token was issued or minted, Unix epoch in milliseconds
                                                                                                        expires_at: number; // When token expires, Unix epoch in milliseconds
                                                                                                        starts_at: number; // When token starts being valid, Unix epoch in milliseconds
                                                                                                        updated_at: number; // When token was last updated, Unix epoch in milliseconds
                                                                                                        extra: string; // anything extra the NFT wants to store on-chain. Can be stringified JSON.
                                                                                                        reference: string; // URL to an off-chain JSON file with more info.
                                                                                                        reference_hash: string; // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
                                                                                                      }
                                                                                                      
                                                                                                      @nearBindgen
                                                                                                      export class Token {
                                                                                                        id: string;
                                                                                                        owner_id: string;
                                                                                                        metadata: TokenMetadata;
                                                                                                        constructor(token_id: string, metadata: TokenMetadata, receiver_id: string) {
                                                                                                          this.id = token_id;
                                                                                                          this.metadata = metadata;
                                                                                                          this.owner_id = receiver_id;
                                                                                                        }
                                                                                                      }
                                                                                                      
                                                                                                      @nearBindgen
                                                                                                      export class ReitToken {
                                                                                                        token: Token;
                                                                                                      
                                                                                                        constructor(token_id: string, metadata: TokenMetadata, receiver_id: string) {
                                                                                                          this.token = { id: token_id, metadata: metadata, owner_id: receiver_id };
                                                                                                        }
                                                                                                        // --- view methods --- //
                                                                                                      
                                                                                                        nft_token(): Token {
                                                                                                          return this.token;
                                                                                                        }
                                                                                                      
                                                                                                        // --- change methods --- //
                                                                                                      
                                                                                                        nft_transfer(
                                                                                                          receiver_id: string,
                                                                                                          token_id: string,
                                                                                                          approval_id: number,
                                                                                                          memo: string
                                                                                                        ): void {
                                                                                                          // assert(false, 'nft_transfer not implemented');
                                                                                                        }
                                                                                                      
                                                                                                        nft_transfer_call(
                                                                                                          receiver_id: string,
                                                                                                          token_id: string,
                                                                                                          approval_id: number,
                                                                                                          memo: string,
                                                                                                          msg: string
                                                                                                        ): ContractPromise {
                                                                                                          // assert(false, 'nft_transfer_call not implemented');
                                                                                                          return ContractPromise.create('', '', {}, 1);
                                                                                                        }
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-19 at 13:48

                                                                                                      After asking around, I was pointed to two different GitHub repositories that implemented an NFT-token smart contract in AssemblyScript.

                                                                                                      After going through those repositories, I noticed that my contract wasn't that far off to be able to display my NFT-tokens in the wallet. I had to implement one more function, nft_metadata().

                                                                                                      I did have metadata in my contract, but as a variable, metadata. Returning the same metadata in nft_metadata() seemed to do the trick

                                                                                                      @nearBindgen
                                                                                                      class NFTContractMetadata {
                                                                                                        constructor(
                                                                                                          public spec: string = 'reit-token-0.0.0', // required, essentially a version like "nft-1.0.0"
                                                                                                          public name: string = 'Reit Token', // required, ex. "Mochi Rising β€” Digital Edition" or "Metaverse 3"
                                                                                                          public symbol: string = 'REIT', // required, ex. "MOCHI"
                                                                                                          public icon: string = '', // Data URL
                                                                                                          public base_uri: string = '', // Centralized gateway known to have reliable access to decentralized storage assets referenced by `reference` or `media` URLs
                                                                                                          public reference: string = '', // URL to a JSON file with more info
                                                                                                          public reference_hash: string = '' // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
                                                                                                        ) {}
                                                                                                      }
                                                                                                      
                                                                                                      @nearBindgen
                                                                                                      export class Contract {
                                                                                                      // ...
                                                                                                      
                                                                                                        nft_metadata(): NFTContractMetadata {
                                                                                                          return new NFTContractMetadata();
                                                                                                        }
                                                                                                      
                                                                                                      // ...
                                                                                                      }
                                                                                                      

                                                                                                      I did override my existing NFT with a new one (transaction found here) while testing, and here it is, visible in the NEAR testnet wallet

                                                                                                      Source https://stackoverflow.com/questions/70739089

                                                                                                      QUESTION

                                                                                                      Getting firestore collection array in to data entity
                                                                                                      Asked 2022-Jan-14 at 07:53

                                                                                                      I'm new in Android Kotlin and I want to GET an array of help in Firestore into my entity and this is my code:

                                                                                                      val appCollection = App.context.db.collection("app")
                                                                                                          val docApp = appCollection.document("info")
                                                                                                          docApp.get().addOnCompleteListener { task ->
                                                                                                              if (task.isSuccessful) {
                                                                                                                  val document = task.result
                                                                                                                  if (document.exists()) {
                                                                                                                      val list = document["help"] as List<*>?
                                                                                                                  }
                                                                                                              }
                                                                                                          }
                                                                                                      

                                                                                                      how can i put that list into my entity, and this is my Entity

                                                                                                      class Info() : Parcelable{
                                                                                                      
                                                                                                      var help: List? = null
                                                                                                      var howto: List? = null
                                                                                                      var info: List? = null
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-14 at 07:52

                                                                                                      As I see in your screenshot, your help array contains objects of type String and not objects of type Help. To read such an array, please change the following field declaration from:

                                                                                                      var help: List? = null
                                                                                                      

                                                                                                      To:

                                                                                                      var help: List? = null
                                                                                                      

                                                                                                      If you however need to store Help in the array, then you need to first add such objects accordingly. So your structure might look like this:

                                                                                                      Firestore-root
                                                                                                        |
                                                                                                        --- app (collection)
                                                                                                             |
                                                                                                              --- info (document)
                                                                                                                   |
                                                                                                                   --- help (array)
                                                                                                                        |
                                                                                                                        --- 0
                                                                                                                            |
                                                                                                                            --- fieldOne: valueOne
                                                                                                                            |
                                                                                                                            --- fieldTwo: valueOTwo
                                                                                                      

                                                                                                      To map such an array to a List of custom objects, please check the following article:

                                                                                                      Source https://stackoverflow.com/questions/70707264

                                                                                                      QUESTION

                                                                                                      Fatal Android 12: Exception: startForegroundService() not allowed due to mAllowStartForeground false
                                                                                                      Asked 2022-Jan-11 at 12:43

                                                                                                      I noticed one exception (Firebase Crashlytics) for Pixel 5 and Pixel 4a (both on Android 12), no other devices, happened only two times, one time for each device.

                                                                                                      What does it mean? Android 11 and 12 have the same rules for working with foreground services, but there are no issues with Android 11. Is this a bug of Pixel?

                                                                                                      From Firebase Crashlytics:

                                                                                                      Fatal Exception: android.app.ForegroundServiceStartNotAllowedException
                                                                                                      startForegroundService() not allowed due to mAllowStartForeground false: service com.helge.droiddashcam/.service.RecorderService
                                                                                                      
                                                                                                      android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
                                                                                                      androidx.core.content.ContextCompat.startForegroundService (ContextCompat.java:6)
                                                                                                      MyAppPackageHidden.service.RecorderService$Companion.startService (RecorderService.java:2)
                                                                                                      MyAppPackageHidden.ui.rec.RecActivity$getConnectionRecorderService$1.onServiceConnected (RecActivity.java:4)
                                                                                                      android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2077)
                                                                                                      com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
                                                                                                      
                                                                                                      Fatal Exception: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service MyAppPackageHidden/.service.RecorderService
                                                                                                             at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
                                                                                                             at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
                                                                                                             at android.os.Parcel.readParcelable(Parcel.java:3333)
                                                                                                             at android.os.Parcel.createExceptionOrNull(Parcel.java:2420)
                                                                                                             at android.os.Parcel.createException(Parcel.java:2409)
                                                                                                             at android.os.Parcel.readException(Parcel.java:2392)
                                                                                                             at android.os.Parcel.readException(Parcel.java:2334)
                                                                                                             at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5971)
                                                                                                             at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1847)
                                                                                                             at android.app.ContextImpl.startForegroundService(ContextImpl.java:1823)
                                                                                                             at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:779)
                                                                                                             at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java)
                                                                                                             at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:6)
                                                                                                             at MyAppPackageHidden.service.RecorderService$Companion.startService(RecorderService.java:2)
                                                                                                             at MyAppPackageHidden.ui.rec.RecActivity$getConnectionRecorderService$1.onServiceConnected(RecActivity.java:4)
                                                                                                             at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2077)
                                                                                                             at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2110)
                                                                                                             at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                             at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                             at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                             at android.os.Looper.loop(Looper.java:288)
                                                                                                             at android.app.ActivityThread.main(ActivityThread.java:7838)
                                                                                                             at java.lang.reflect.Method.invoke(Method.java)
                                                                                                             at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
                                                                                                      
                                                                                                      Caused by android.os.RemoteException: Remote stack trace:
                                                                                                          at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:691)
                                                                                                          at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:616)
                                                                                                          at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:11839)
                                                                                                          at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2519)
                                                                                                          at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2498)
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-11 at 12:43

                                                                                                      Apps that target Android 12 (API level 31) or higher can't start foreground services while running in the background, except for a few special cases. If an app tries to start a foreground service while the app is running in the background, and the foreground service doesn't satisfy one of the exceptional cases, the system throws a ForegroundServiceStartNotAllowedException.

                                                                                                      Exemptions from background start restrictions

                                                                                                      In the following situations, your app can start foreground services even while your app is running in the background:

                                                                                                      • Your app transitions from a user-visible state, such as an activity.
                                                                                                      • Your app can start an activity from the background, except for the case where the app has an activity in the back stack of an existing task.
                                                                                                      • Your app receives a high-priority message using Firebase Cloud Messaging.
                                                                                                      • The user performs an action on a UI element related to your app. For example, they might interact with a bubble, notification, widget, or activity.
                                                                                                      • Your app invokes an exact alarm to complete an action that the user requests.
                                                                                                      • Your app is the device's current input method.
                                                                                                      • Your app receives an event that's related to geofencing or activity recognition transition.
                                                                                                      • After the device reboots and receives the ACTION_BOOT_COMPLETED, ACTION_LOCKED_BOOT_COMPLETED, or ACTION_MY_PACKAGE_REPLACED intent action in a broadcast receiver.

                                                                                                      For more info please check link1 link2

                                                                                                      Source https://stackoverflow.com/questions/70044393

                                                                                                      QUESTION

                                                                                                      Removing items with a transition prevents them from being added during that period
                                                                                                      Asked 2022-Jan-06 at 11:29

                                                                                                      I have some data that occasionally has data removed, and added. This doesn't often, but can, happen in quick succession.

                                                                                                      I've found that the dataGroups.exit().transition()....remove() 'overrides' the enter dataGroups.enter(...).append(...).transition().

                                                                                                      It seems when an item is being removed, then 'enters' again, it fails to stop the removal process, so the item gets left either removed, or in the removed state (e.g. transparent or size 0).

                                                                                                      Here's a working example, click the button slowly and it works as expected, but too fast and you'll get the lower bar missing when it should be there.

                                                                                                      I've tried adding interupt() to try interrupt the exit animation but it doesn't seem to work. Can't find any reference to this, but I'm surprised it's not an issue someone has seen before and come up with a solution:

                                                                                                      const dataset1 = [
                                                                                                        { name: "item 1", value: 200 },
                                                                                                        { name: "item 2", value: 100 }
                                                                                                      ];
                                                                                                      const dataset2 = [{ name: "item 1", value: 100 }];
                                                                                                      let currentDataset = undefined;
                                                                                                      
                                                                                                      function refresh() {
                                                                                                        const newDataset = currentDataset === dataset1 ? dataset2 : dataset1;
                                                                                                        currentDataset = newDataset;
                                                                                                      
                                                                                                        // Join new data with old elements, if any.
                                                                                                        const dataGroups = d3
                                                                                                          .select(".vis")
                                                                                                          .selectAll(".box")
                                                                                                          .data(newDataset, (d) => d.name);
                                                                                                      
                                                                                                        // Remove old elements as needed.
                                                                                                        dataGroups
                                                                                                          .exit()
                                                                                                          .transition("remove")
                                                                                                          .duration(400)
                                                                                                          .attr("opacity", 0.2)
                                                                                                          .remove();
                                                                                                      
                                                                                                        // Create new elements as needed.
                                                                                                        const newGroups = dataGroups
                                                                                                          .enter()
                                                                                                          .append("rect")
                                                                                                          .attr("class", "box")
                                                                                                          .attr("height", 10);
                                                                                                      
                                                                                                        newGroups.transition("add").duration(400).attr("opacity", 1);
                                                                                                      
                                                                                                        // Merge and update
                                                                                                        newGroups
                                                                                                          .merge(dataGroups)
                                                                                                          .attr("width", (d) => d.value)
                                                                                                          .attr("y", (d, i) => i * 12);
                                                                                                      }
                                                                                                      
                                                                                                      document.getElementById("button").onclick = () => {
                                                                                                        refresh();
                                                                                                      };
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                        
                                                                                                          Parcel Sandbox
                                                                                                          
                                                                                                        
                                                                                                      
                                                                                                        
                                                                                                          Update data
                                                                                                      
                                                                                                          
                                                                                                      
                                                                                                          

                                                                                                      Click the button slowly, and see it add and remove elements with a transition

                                                                                                      Click the button twice in quick succession, and see it doesn't correctly represent the data

                                                                                                      It should look like:

                                                                                                      |====
                                                                                                      |==
                                                                                                              

                                                                                                      Or:

                                                                                                      |==
                                                                                                      |
                                                                                                              

                                                                                                      Never:

                                                                                                      |====
                                                                                                      |
                                                                                                              

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-06 at 11:28

                                                                                                      First of all, it should be noticed that D3 selections are immutable, so using merge on your enter selection the way you're doing has no effect. Also, you should set the opacity of the enter selection to 0 if you want to properly see the transition.

                                                                                                      Back to the question, the problem here is that the exiting bar is counted when you select all elements with box class, and because of that your enter selection is empty. The simplest solution is using selection.interrupt(). Contrary to what you said interrupt does work, but the issue is just that because you named your exit transition, you need to use the same name:

                                                                                                        dataGroups.interrupt("remove");
                                                                                                      

                                                                                                      Here is your code with that change:

                                                                                                      const dataset1 = [{
                                                                                                          name: "item 1",
                                                                                                          value: 200
                                                                                                        },
                                                                                                        {
                                                                                                          name: "item 2",
                                                                                                          value: 100
                                                                                                        }
                                                                                                      ];
                                                                                                      const dataset2 = [{
                                                                                                        name: "item 1",
                                                                                                        value: 100
                                                                                                      }];
                                                                                                      let currentDataset = undefined;
                                                                                                      
                                                                                                      function refresh() {
                                                                                                        const newDataset = currentDataset === dataset1 ? dataset2 : dataset1;
                                                                                                        currentDataset = newDataset;
                                                                                                      
                                                                                                        // Join new data with old elements, if any.
                                                                                                        let dataGroups = d3
                                                                                                          .select(".vis")
                                                                                                          .selectAll(".box")
                                                                                                          .data(newDataset, (d) => d.name);
                                                                                                      
                                                                                                        dataGroups.interrupt("remove");
                                                                                                        
                                                                                                        dataGroups.attr("opacity", 1);
                                                                                                      
                                                                                                        // Remove old elements as needed.
                                                                                                        dataGroups
                                                                                                          .exit()
                                                                                                          .transition("remove")
                                                                                                          .duration(400)
                                                                                                          .attr("opacity", 0.2)
                                                                                                          .remove();
                                                                                                      
                                                                                                        // Create new elements as needed.
                                                                                                        const newGroups = dataGroups
                                                                                                          .enter()
                                                                                                          .append("rect")
                                                                                                          .attr("class", "box")
                                                                                                          .attr("height", 10)
                                                                                                          .attr("opacity", 0)
                                                                                                      
                                                                                                        newGroups.transition("add").duration(400).attr("opacity", 1);
                                                                                                      
                                                                                                        // Merge and update
                                                                                                        dataGroups = newGroups.merge(dataGroups);
                                                                                                      
                                                                                                        dataGroups.attr("width", (d) => d.value)
                                                                                                          .attr("y", (d, i) => i * 12);
                                                                                                      }
                                                                                                      
                                                                                                      document.getElementById("button").onclick = () => {
                                                                                                        refresh();
                                                                                                      };
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                        Parcel Sandbox
                                                                                                        
                                                                                                      
                                                                                                      
                                                                                                      
                                                                                                        Update data
                                                                                                      
                                                                                                        
                                                                                                      
                                                                                                        

                                                                                                      Click the button slowly, and see it add and remove elements with a transition

                                                                                                      Click the button twice in quick succession, and see it doesn't correctly represent the data

                                                                                                      It should look like:

                                                                                                      |====
                                                                                                      |==
                                                                                                              

                                                                                                      Or:

                                                                                                      |==
                                                                                                      |
                                                                                                              

                                                                                                      Never:

                                                                                                      |====
                                                                                                      |
                                                                                                              

                                                                                                      Also, I put a dataGroups.attr("opacity", 1); just after interrupting the transition, so we return the opacity of the fading bar to 1.

                                                                                                      Source https://stackoverflow.com/questions/70596918

                                                                                                      QUESTION

                                                                                                      Android Studio Kotlin Null Pointer Exception while updating Firestore Database
                                                                                                      Asked 2021-Dec-27 at 16:59

                                                                                                      I've recently stumbled upon a runtime error that crashes my application for whatever reason and I cannot get to the bottom of it. Basically I am updating user profile data by storing it in a hashmap. This is what the user class looks like:

                                                                                                      @Parcelize
                                                                                                      data class User(
                                                                                                          val id: String = "",
                                                                                                          val firstName: String = "",
                                                                                                          val lastName: String = "",
                                                                                                          val email: String = "",
                                                                                                          val image: String = "",
                                                                                                          val mobile: Long = 0,
                                                                                                          val gender: String = "",
                                                                                                          val profileCompleted: Int = 0): Parcelable
                                                                                                      

                                                                                                      In an activity I called UserProfileActivity I store the mobile and gender into a hashmap, then call the Firebase function to update the Firestore Database. Here is a method of the activity. When the button "submit" is clicked, this code runs:

                                                                                                      btn_submit.setOnClickListener {
                                                                                                                  if(validateUserProfileDetails()){  //checks if entered credentials are valid
                                                                                                                      val userHashMap = HashMap()  //creates the hashmap
                                                                                                      
                                                                                                                      val mobileNumber = et_mobile_number.text.toString().trim { it <= ' ' }
                                                                                                      
                                                                                                                      val gender = if (rb_male.isChecked) {  //these are radio buttons, only 1 clicked
                                                                                                                          Constants.MALE
                                                                                                                      } else {
                                                                                                                          Constants.FEMALE
                                                                                                                      }
                                                                                                      
                                                                                                                      userHashMap[Constants.MOBILE] = mobileNumber.toLong()  //storing info in hashmap
                                                                                                      
                                                                                                                      userHashMap[Constants.GENDER] = gender
                                                                                                      
                                                                                                                      showProgressDialog(resources.getString(R.string.please_wait))  //starting a progress dialog
                                                                                                      
                                                                                                                      FirestoreClass().updateUserProfileData(  //method in FirestoreClass 
                                                                                                                          this, userHashMap
                                                                                                                      )
                                                                                                                  }
                                                                                                              }
                                                                                                      

                                                                                                      Now the called method that communicates with the database:

                                                                                                      fun updateUserProfileData(activity: Activity, userHashMap: HashMap) {
                                                                                                              mFireStore.collection(Constants.USERS)  // collection named "users"
                                                                                                                  .document(getCurrentUserID())  //getCurrentUserID() just gets the current user id 
                                                                                                                  .update(userHashMap)  // hashmap used to update the user
                                                                                                                  .addOnSuccessListener {
                                                                                                                      when (activity) {
                                                                                                                          is UserProfileActivity -> {
                                                                                                                              activity.userProfileUpdateSuccess() //this just hides the progress dialog and finishes the activity in the UserProfileActivity
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                                  .addOnFailureListener { e ->
                                                                                                                      when (activity) {
                                                                                                                          is UserProfileActivity -> {
                                                                                                                              activity.hideProgressDialog()
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                      
                                                                                                      
                                                                                                      }
                                                                                                      

                                                                                                      But I am getting this error:

                                                                                                      2021-12-27 02:35:38.727 14960-14960/com.example.myshopapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                                      Process: com.example.myshopapp, PID: 14960
                                                                                                      java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter it
                                                                                                          at com.example.myshopapp.firestore.FirestoreClass.updateUserProfileData$lambda-2(Unknown Source:7)
                                                                                                          at com.example.myshopapp.firestore.FirestoreClass.$r8$lambda$vs4EuaGwStcL-i3lXRUecduDHWM(Unknown Source:0)
                                                                                                          at com.example.myshopapp.firestore.FirestoreClass$$ExternalSyntheticLambda4.onSuccess(Unknown Source:4)
                                                                                                          at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.0:1)
                                                                                                          at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                          at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                          at android.os.Looper.loop(Looper.java:223)
                                                                                                          at android.app.ActivityThread.main(ActivityThread.java:7656)
                                                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
                                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
                                                                                                      

                                                                                                      I have absolutely no clue where the null pointer exception is occuring... And funnily enough (this is important), the database DOES get updated properly so why is it crashing?? Any help would be much appreciated. :)

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-27 at 16:59

                                                                                                      This specific error has been showing up a lot lately, and seems to be due to an inconsistent nullability annotation in Firebase listeners.

                                                                                                      Apparently Google is aware of the issue and may have recently fixed it

                                                                                                      When adding an onSuccessListener for an update call in Kotlin it infers a non-null type for it (Void not Void?). This means if Firestore returns a null result (which would not be uncommon for a Void argument from java), it will raise the error you showed when it is cast to a non-null parameter. The solution is to update to the latest version that fixes this, or if you need an immediate workaround to specifically set the type to nullable, so to change

                                                                                                      .addOnSuccessListener { 
                                                                                                          println("Updated doc")
                                                                                                      }
                                                                                                      

                                                                                                      to

                                                                                                      .addOnSuccessListener { _: Void? ->
                                                                                                          println("Updated doc")
                                                                                                      }
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/70491011

                                                                                                      QUESTION

                                                                                                      Android how to sort RecyclerView List when using AsyncListDiffer?
                                                                                                      Asked 2021-Dec-24 at 15:36

                                                                                                      I have a RecyclerView that shows a list of CardViews. I recently switched the project from using RecyclerView Adapter to using an AsyncListDiffer Adapter to take advantage of adapter updates on a background thread. I have converted over all previous CRUD and filter methods for the list but cannot get the sort method working.

                                                                                                      I have different types or categories of CardViews and I would like to sort by the types/categories. I clone the existing list mCards so the "behind the scenes" DiffUtil will see it as a different list, as compared to the existing list that I wanted to sort. And then I use AsynListDiffer's submitList().

                                                                                                      The list is not sorting. What am I missing here?

                                                                                                      MainActivity:

                                                                                                      private static List mCards = null;
                                                                                                      
                                                                                                      ...
                                                                                                      mCardViewModel = new ViewModelProvider(this).get(CardViewModel.class);
                                                                                                      mCardViewModel.getAllCards().observe(this,(cards -> {
                                                                                                      
                                                                                                          mCards = cards;
                                                                                                          cardsAdapter.submitList(mCards);
                                                                                                      })); 
                                                                                                      mRecyclerView.setAdapter(cardsAdapter);
                                                                                                      
                                                                                                      A click on a "Sort" TextView runs the following code:
                                                                                                      
                                                                                                      ArrayList sortItems = new ArrayList<>();
                                                                                                      for (Card card : mCards) {
                                                                                                          sortItems.add(card.clone());
                                                                                                      }
                                                                                                      Collections.sort(sortItems, new Comparator() {
                                                                                                          @Override
                                                                                                          public int compare(Card cardFirst, Card cardSecond) {
                                                                                                              return cardFirst.getType().compareTo(cardSecond.getType());
                                                                                                          }
                                                                                                      });
                                                                                                      cardsAdapter.submitList(sortItems);
                                                                                                      // mRecyclerView.setAdapter(cardsAdapter);  // Adding this did not help
                                                                                                      

                                                                                                      AsyncListDifferAdapter:

                                                                                                      public AsyncListDifferAdapter(Context context) {
                                                                                                      
                                                                                                          this.mListItems = new AsyncListDiffer<>(this, DIFF_CALLBACK);
                                                                                                          this.mContext = context;
                                                                                                          this.mInflater = LayoutInflater.from(mContext);
                                                                                                      }
                                                                                                      
                                                                                                      public void submitList(List list) {
                                                                                                      
                                                                                                          if (list != null) {
                                                                                                              mListItems.submitList(list);
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      public static final DiffUtil.ItemCallback DIFF_CALLBACK
                                                                                                              = new DiffUtil.ItemCallback() {
                                                                                                      
                                                                                                          @Override
                                                                                                          public boolean areItemsTheSame(@NonNull Card oldItem, @NonNull Card newItem) {
                                                                                                      
                                                                                                              // User properties may have changed if reloaded from the DB, but ID is fixed
                                                                                                              return oldItem.getId() == newItem.getId();
                                                                                                          }
                                                                                                          @Override
                                                                                                          public boolean areContentsTheSame(@NonNull Card oldItem, @NonNull Card newItem) {
                                                                                                              return oldItem.equals(newItem);
                                                                                                          }
                                                                                                      
                                                                                                          @Nullable
                                                                                                          @Override
                                                                                                          public Object getChangePayload(@NonNull Card oldItem, @NonNull Card newItem) {
                                                                                                              return super.getChangePayload(oldItem, newItem);
                                                                                                          }
                                                                                                      };
                                                                                                      

                                                                                                      Model:

                                                                                                      @Entity(tableName = "cards")
                                                                                                      public class Card implements Parcelable, Cloneable {
                                                                                                      // Parcelable code not shown for brevity
                                                                                                      @PrimaryKey(autoGenerate = true)
                                                                                                      @ColumnInfo(name = "cardId")
                                                                                                      public int id;
                                                                                                      @ColumnInfo(name = "cardType")
                                                                                                      private String type;
                                                                                                      
                                                                                                      @Ignore
                                                                                                      public Card(int id, String type) {
                                                                                                          this.id = id;
                                                                                                          this.type = type;
                                                                                                      }
                                                                                                      
                                                                                                      public int getId() {
                                                                                                          return this.id;
                                                                                                      }
                                                                                                      public String getType() {
                                                                                                          return this.type;
                                                                                                      }
                                                                                                      
                                                                                                      @Override
                                                                                                      public boolean equals(Object obj) {
                                                                                                      
                                                                                                          if (obj == this)
                                                                                                              return true;
                                                                                                      
                                                                                                          else if (obj instanceof Card) {
                                                                                                      
                                                                                                              Card card = (Card) obj;
                                                                                                      
                                                                                                              return id == card.getId() &&
                                                                                                                  type.equals(card.getType());
                                                                                                          } else {
                                                                                                              return false;
                                                                                                          }
                                                                                                      }  
                                                                                                      
                                                                                                      @NonNull
                                                                                                      @Override
                                                                                                      public Card clone() {
                                                                                                          Card clone;
                                                                                                          try {
                                                                                                              clone = (Card) super.clone();
                                                                                                          } catch (CloneNotSupportedException e) {
                                                                                                              throw new RuntimeException(e);
                                                                                                          }
                                                                                                          return clone;
                                                                                                      }  
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-22 at 05:40

                                                                                                      I think issue is in below method

                                                                                                      public void submitList(List list) {
                                                                                                          
                                                                                                              if (list != null) {
                                                                                                                  mListItems.submitList(list);
                                                                                                              }
                                                                                                      }
                                                                                                      

                                                                                                      because here first you need to clear old arraylist "mListItems" using

                                                                                                      mListItems.clear();
                                                                                                      //then add new data 
                                                                                                       
                                                                                                      
                                                                                                      if (list != null) {
                                                                                                          mListItems.addAll(list);
                                                                                                      }
                                                                                                       
                                                                                                      //now notify adapter
                                                                                                      notifyDataSetChanged();
                                                                                                      

                                                                                                      Or Also you can direct notify adapter after sorting. First set adapter and pass your main list in adapter's constructor

                                                                                                      Collections.sort(sortItems, new Comparator() {
                                                                                                      @Override
                                                                                                      public int compare(Card cardFirst, Card cardSecond) {
                                                                                                          return cardFirst.getType().compareTo(cardSecond.getType());
                                                                                                      }
                                                                                                      

                                                                                                      });

                                                                                                      //now direct notify adpter
                                                                                                      your_adapter_object.notifyDataSetChanged();
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/70318907

                                                                                                      QUESTION

                                                                                                      Getting android.app.ForegroundServiceStartNotAllowedException in Android 12 (SDK 31)
                                                                                                      Asked 2021-Dec-17 at 11:23

                                                                                                      I upgraded my apps targetSdkVersion and compileSdkVersion to SDK 31, and started receiving the following crash in app in a service that updates widget in background.

                                                                                                      java.lang.RuntimeException: 
                                                                                                        at android.app.ActivityThread.handleReceiver (ActivityThread.java:4321)
                                                                                                        at android.app.ActivityThread.access$1600 (ActivityThread.java:247)
                                                                                                        at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2068)
                                                                                                        at android.os.Handler.dispatchMessage (Handler.java:106)
                                                                                                        at android.os.Looper.loopOnce (Looper.java:201)
                                                                                                        at android.os.Looper.loop (Looper.java:288)
                                                                                                        at android.app.ActivityThread.main (ActivityThread.java:7842)
                                                                                                        at java.lang.reflect.Method.invoke (Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
                                                                                                        at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
                                                                                                      Caused by: android.app.ForegroundServiceStartNotAllowedException: 
                                                                                                        at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
                                                                                                        at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:50)
                                                                                                        at android.os.Parcel.readParcelable (Parcel.java:3333)
                                                                                                        at android.os.Parcel.createExceptionOrNull (Parcel.java:2420)
                                                                                                        at android.os.Parcel.createException (Parcel.java:2409)
                                                                                                        at android.os.Parcel.readException (Parcel.java:2392)
                                                                                                        at android.os.Parcel.readException (Parcel.java:2334)
                                                                                                        at android.app.IActivityManager$Stub$Proxy.startService (IActivityManager.java:5971)
                                                                                                        at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1847)
                                                                                                        at android.app.ContextImpl.startForegroundService (ContextImpl.java:1823)
                                                                                                        at android.content.ContextWrapper.startForegroundService (ContextWrapper.java:779)
                                                                                                        at android.content.ContextWrapper.startForegroundService (ContextWrapper.java:779)
                                                                                                        at com.mypackage.appname.ui.widget.widget_package.WidgetClassName.onUpdate (WidgetClassName.java:48)
                                                                                                        at android.appwidget.AppWidgetProvider.onReceive (AppWidgetProvider.java:66)
                                                                                                        at com.mypackage.appname.ui.widget.widget_package.WidgetClassName.onReceive (WidgetClassName.java)
                                                                                                        at android.app.ActivityThread.handleReceiver (ActivityThread.java:4312)
                                                                                                        at android.app.ActivityThread.access$1600 (ActivityThread.java:247)
                                                                                                        at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2068)
                                                                                                        at android.os.Handler.dispatchMessage (Handler.java:106)
                                                                                                        at android.os.Looper.loopOnce (Looper.java:201)
                                                                                                        at android.os.Looper.loop (Looper.java:288)
                                                                                                        at android.app.ActivityThread.main (ActivityThread.java:7842)
                                                                                                        at java.lang.reflect.Method.invoke (Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
                                                                                                        at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
                                                                                                      Caused by: android.os.RemoteException: 
                                                                                                        at com.android.server.am.ActiveServices.startServiceLocked (ActiveServices.java:691)
                                                                                                        at com.android.server.am.ActiveServices.startServiceLocked (ActiveServices.java:616)
                                                                                                        at com.android.server.am.ActivityManagerService.startService (ActivityManagerService.java:11839)
                                                                                                        at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:2519)
                                                                                                        at com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:2498)
                                                                                                      

                                                                                                      Also, if you're using something like Firebase Crashlytics, your stacktrace must be something like this ->

                                                                                                      Caused by android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.mypackage.appname/.ui.widget.widget_package.MyForegroundServiceName
                                                                                                             at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
                                                                                                             at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
                                                                                                             at android.os.Parcel.readParcelable(Parcel.java:3333)
                                                                                                             at android.os.Parcel.createExceptionOrNull(Parcel.java:2420)
                                                                                                             at android.os.Parcel.createException(Parcel.java:2409)
                                                                                                             at android.os.Parcel.readException(Parcel.java:2392)
                                                                                                             at android.os.Parcel.readException(Parcel.java:2334)
                                                                                                             at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:5971)
                                                                                                             at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1847)
                                                                                                             at android.app.ContextImpl.startForegroundService(ContextImpl.java:1823)
                                                                                                             at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:779)
                                                                                                             at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:779)
                                                                                                             at com.mypackage.appname.ui.widget.widget_package.WidgetClassName.onUpdate(WidgetClassName.java:48)
                                                                                                             at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:66)
                                                                                                             at com.mypackage.appname.ui.widget.widget_package.WidgetClassName.onReceive(WidgetClassName.java)
                                                                                                             at android.app.ActivityThread.handleReceiver(ActivityThread.java:4312)
                                                                                                             at android.app.ActivityThread.access$1600(ActivityThread.java:247)
                                                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2068)
                                                                                                             at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                             at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                             at android.os.Looper.loop(Looper.java:288)
                                                                                                             at android.app.ActivityThread.main(ActivityThread.java:7842)
                                                                                                             at java.lang.reflect.Method.invoke(Method.java)
                                                                                                             at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
                                                                                                      

                                                                                                      I'm adding the way to reproduce this issue, and fixes to this problem, because I did not find any documentation about this on StackOverflow when I searched for it.

                                                                                                      ANSWER

                                                                                                      Answered 2021-Oct-17 at 13:49
                                                                                                      How to reproduce the crash

                                                                                                      Step 1. Update your targetSdkVersion and compileSdkVersion to SDK 31.

                                                                                                      Step 2. Try to run any Foreground service when your app is in background. In my case, it was the widget's onUpdate method being called after updatePeriodMillis time, which will start a Foreground service, which updates the data by fetching appropriate information from internet.

                                                                                                      Remember: The background execution limits added in Android 8.0 have nothing to do with this problem. This limitation/exception was added in Android 12/SDK 31 - Source.

                                                                                                      What is this exception, and why was it added?

                                                                                                      Apps that target Android 12 (API level 31) or higher can't start foreground services while running in the background, except for a few special cases. If an app tries to start a foreground service while the app is running in the background, and the foreground service doesn't satisfy one of the exceptional cases, the system throws a ForegroundServiceStartNotAllowedException.

                                                                                                      These special cases are:

                                                                                                      • Your app transitions from a user-visible state, such as an activity.

                                                                                                      • Your app can start an activity from the background, except for the case where the app has an activity in the back stack of an existing task.

                                                                                                      • Your app receives a high-priority message using Firebase Cloud Messaging.

                                                                                                      • The user performs an action on a UI element related to your app. For example, they might interact with a bubble, notification, widget, or activity.

                                                                                                      • Your app invokes an exact alarm to complete an action that the user requests.

                                                                                                      • Your app is the device's current input method.

                                                                                                      • Your app receives an event that's related to geofencing or activity recognition transition.

                                                                                                      • After the device reboots and receives the ACTION_BOOT_COMPLETED, ACTION_LOCKED_BOOT_COMPLETED, or ACTION_MY_PACKAGE_REPLACED intent action in a broadcast receiver.

                                                                                                      • Your app receives the ACTION_TIMEZONE_CHANGED, ACTION_TIME_CHANGED, or ACTION_LOCALE_CHANGED intent action in a broadcast receiver.

                                                                                                      • Your app receives a Bluetooth broadcast that requires the BLUETOOTH_CONNECT or BLUETOOTH_SCAN permissions.

                                                                                                      • Apps with certain system roles or permission, such as device owners and profile owners.

                                                                                                      • Your app uses the Companion Device Manager and declares the REQUEST_COMPANION_START_FOREGROUND_SERVICES_FROM_BACKGROUND permission or the REQUEST_COMPANION_RUN_IN_BACKGROUND permission. Whenever possible, use REQUEST_COMPANION_START_FOREGROUND_SERVICES_FROM_BACKGROUND.

                                                                                                      • The user turns off battery optimizations for your app. You can help users find this option by sending them to your app's App info page in system settings. To do so, invoke an intent that contains the ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS intent action.

                                                                                                      Possible solutions Solution 1

                                                                                                      This will work for a while in Play Store until Google makes it mandatory to upgrade to API level 31.

                                                                                                      Currently, starting November 2021 all apps must target API Level 30 and above. So if you're using API Level 31 for your app, downgrading your compileSdkVersion & targetSdkVersion to API Level 30 should fix the issue (atleast for a while).

                                                                                                      Solution 2 For time-sensitive work

                                                                                                      If you were using Foreground service to do work that is time sensitive, start Foreground services within an exact alarm. Check out more about this from documentation here -> Set an exact alarm.

                                                                                                      For time-insensitive/expedited work

                                                                                                      This is the solution that I ended up using for my app. Use WorkManager to schedule and start the background work. Check out more about this from documentation here -> Schedule expedited work.

                                                                                                      You can know more about WorkManager here -> WorkManager

                                                                                                      Github Repo for WorkManager samples -> WorkManager Samples

                                                                                                      I added this answer specifically because searching for this exception does not bring up any resources to know why the service behaves differently on Android 12. All this is present in Google's documentation, and always remember to check the behaviour changes from the doc.

                                                                                                      Everything related to this change can be found here -> Android 12 Behavior Changes, specifically within the Foreground Service launch restrictions.

                                                                                                      Source https://stackoverflow.com/questions/69604951

                                                                                                      QUESTION

                                                                                                      st_buffer "missing" part of multipolygon using sf in R
                                                                                                      Asked 2021-Dec-15 at 08:27

                                                                                                      I am using the sf package in R along with the arcpullr package to pull in data from an ArcGIS REST service and work with it as an sf object. I have run into an issue with a MULTIPOLYGON where sf is only buffering a part of the MULTIPOLYGON (i.e., it buffers one polygon but only tiny slivers of the other). I have not been able to replicate the problem when buffering the example found here.

                                                                                                      Here is an MRE (sorry, you'll have to install arcpullr if you don't have it).

                                                                                                      # install.packages("arcpullr")
                                                                                                      library(arcpullr)
                                                                                                      library(sf) # redundant since loaded with arcpullr, but here for brevity
                                                                                                      library(ggplot2)
                                                                                                      
                                                                                                      tax_parcel_url <- paste0(
                                                                                                        "https://mapservices.legis.wisconsin.gov/arcgis/rest/services/", 
                                                                                                        "WLIP/Parcels/FeatureServer/0"
                                                                                                      )
                                                                                                      parcel <- 
                                                                                                        get_spatial_layer(tax_parcel_url, where = "PARCELID = 'HA-11'") %>%
                                                                                                        st_transform(crs = 3071)
                                                                                                      parcel_buffer <- st_buffer(parcel, dist = 10)
                                                                                                      
                                                                                                      # map of parcel
                                                                                                      ggplot(data = parcel) + geom_sf() # this is correct
                                                                                                      
                                                                                                      # map of parcel and buffer - buffer "misses" part of multipolygon
                                                                                                      ggplot(data = parcel_buffer) + 
                                                                                                        geom_sf(color = "blue") + 
                                                                                                        geom_sf(data = parcel, color = "red", alpha = 0.3) + 
                                                                                                        theme_bw()
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-15 at 08:27

                                                                                                      You can pipe in st_make_valid to parcel, which will correct the geometry with the sf object (i.e., make the geometry valid). This will allow for the buffer to plot correctly on all parts of the multipolygon.

                                                                                                      library(arcpullr)
                                                                                                      library(sf)
                                                                                                      library(ggplot2)
                                                                                                      
                                                                                                      parcel <-
                                                                                                        arcpullr::get_spatial_layer(tax_parcel_url, where = "PARCELID = 'HA-11'") %>%
                                                                                                        sf::st_transform(crs = 3071) %>%
                                                                                                        sf::st_make_valid()
                                                                                                      
                                                                                                      parcel_buffer <- sf::st_buffer(parcel, dist = 10)
                                                                                                      
                                                                                                      ggplot(data = parcel_buffer) +
                                                                                                        geom_sf(color = "blue") +
                                                                                                        geom_sf(data = parcel,
                                                                                                                color = "red",
                                                                                                                alpha = 0.3) +
                                                                                                        theme_bw()
                                                                                                      

                                                                                                      Output

                                                                                                      Mapview

                                                                                                      You can see that the buffer is clear in mapview as well.

                                                                                                      library(mapview)
                                                                                                      
                                                                                                      mapview::mapview(parcel_buffer) + mapview::mapview(parcel)
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/70265992

                                                                                                      QUESTION

                                                                                                      Abstract database methods must return a @Dao annotated class or interface
                                                                                                      Asked 2021-Dec-14 at 04:32

                                                                                                      I think this topic already existed. But, since we have a new version of room database, it will be helpful to me to understand better. So, I am implementing a room database with the version 2.3.0 but I am getting lot of errors:

                                                                                                      1. Type of the parameter must be a class annotated with @Entity or a collection/array of it. kotlin.coroutines.Continuation continuation);
                                                                                                      2. Not sure how to handle insert method's return type. public abstract java.lang.Object insertStudent(@org.jetbrains.annotations.NotNull()
                                                                                                      3. Abstract database methods must return a @Dao annotated class or interface. public abstract void setConnectDatabaseDao(@org.jetbrains.annotations.NotNull()

                                                                                                      Like said here, I added ktx extension to support suspendable meethods in Dao. But it's still giving me these errors. Here are my code : app build gradle

                                                                                                      plugins {
                                                                                                          id 'com.android.application'
                                                                                                          id 'kotlin-android-extensions'
                                                                                                          id 'kotlin-android'
                                                                                                          //id 'kotlin-parcelize'
                                                                                                      }
                                                                                                      apply plugin: 'kotlin-kapt'
                                                                                                      ...
                                                                                                      //room data base
                                                                                                          implementation "androidx.room:room-runtime:$room_version"
                                                                                                          annotationProcessor "androidx.room:room-compiler:$room_version"
                                                                                                          implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
                                                                                                          kapt "androidx.lifecycle:lifecycle-compiler:2.4.0"
                                                                                                          kapt "androidx.room:room-compiler:$room_version"
                                                                                                          implementation "androidx.room:room-ktx:$room_version"
                                                                                                      
                                                                                                          // optional - RxJava2 support for Room
                                                                                                          implementation "androidx.room:room-rxjava2:$room_version"
                                                                                                      
                                                                                                      
                                                                                                          // optional - Guava support for Room, including Optional and ListenableFuture
                                                                                                          implementation "androidx.room:room-guava:$room_version"
                                                                                                      
                                                                                                          // optional - Test helpers
                                                                                                          testImplementation "androidx.room:room-testing:$room_version"
                                                                                                      
                                                                                                          // optional - Paging 3 Integration
                                                                                                          implementation "androidx.room:room-paging:2.4.0-rc01"
                                                                                                      

                                                                                                      Database

                                                                                                      @Database(entities = [Skill::class, Student::class], version = 1, exportSchema = false)
                                                                                                      abstract class ConnectDatabase():RoomDatabase() {
                                                                                                      
                                                                                                          abstract var connectDatabaseDao:ConnectDatabaseDao
                                                                                                          companion object{
                                                                                                              @Volatile
                                                                                                              var INSTANCE:ConnectDatabase? = null
                                                                                                              fun getInstance(context:Context): ConnectDatabase {
                                                                                                                  synchronized(this) {
                                                                                                                      var instance = INSTANCE
                                                                                                                      if (instance == null) {
                                                                                                                          instance = Room.databaseBuilder(
                                                                                                                              context,
                                                                                                                              ConnectDatabase::class.java,
                                                                                                                              "connect_database"
                                                                                                                          )
                                                                                                                              .fallbackToDestructiveMigration()
                                                                                                                              .build()
                                                                                                                          INSTANCE = instance
                                                                                                                      }
                                                                                                                      return instance
                                                                                                                  }
                                                                                                              }
                                                                                                          }
                                                                                                      
                                                                                                      }
                                                                                                      

                                                                                                      Dao

                                                                                                      
                                                                                                      @Dao
                                                                                                      interface ConnectDatabaseDao {
                                                                                                          @Insert(onConflict = OnConflictStrategy.REPLACE)
                                                                                                          suspend fun insertStudent(student: Student)
                                                                                                      
                                                                                                          @Insert(onConflict = OnConflictStrategy.REPLACE)
                                                                                                          suspend fun insertSkill (skill: Skill)
                                                                                                      
                                                                                                          @Delete
                                                                                                          suspend fun deleteStudent(student: Student)
                                                                                                      
                                                                                                          @Delete
                                                                                                          suspend fun deleteSkill(skill: Skill)
                                                                                                      
                                                                                                          @Query("SELECT * FROM student WHERE id = :id")
                                                                                                          suspend fun getStudent(id:Long):Student?
                                                                                                      
                                                                                                          @Query("SELECT * FROM skill WHERE id = :id")
                                                                                                          suspend fun getSkill(id:Long):Skill?
                                                                                                      
                                                                                                          @Query("SELECT * FROM student")
                                                                                                          fun getAllStudent():LiveData?>
                                                                                                      
                                                                                                          @Query("SELECT * FROM skill")
                                                                                                          fun getAllSkill():LiveData?>
                                                                                                      
                                                                                                      }
                                                                                                      

                                                                                                      Data class

                                                                                                      @Parcelize
                                                                                                      @Entity(tableName = "student",
                                                                                                          foreignKeys = arrayOf(
                                                                                                              ForeignKey(entity = Skill::class,
                                                                                                                  parentColumns = arrayOf("id"),
                                                                                                                  childColumns = arrayOf("id_skill"),
                                                                                                                  onDelete = ForeignKey.CASCADE
                                                                                                                  )
                                                                                                              )
                                                                                                      )
                                                                                                      data class Student (
                                                                                                              @PrimaryKey(autoGenerate = true)
                                                                                                              @ColumnInfo(name = "id")
                                                                                                              val id: Long,
                                                                                                      
                                                                                                              @ColumnInfo(name = "name")
                                                                                                              val name: String,
                                                                                                      
                                                                                                              @ColumnInfo(name= "email")
                                                                                                              val email: String,
                                                                                                      
                                                                                                              @ColumnInfo(name = "id_skill")
                                                                                                              val idSkill: Long
                                                                                                              ):Parcelable
                                                                                                      @Parcelize
                                                                                                      @Entity(tableName = "skill")
                                                                                                      data class Skill (
                                                                                                          @PrimaryKey(autoGenerate = true)
                                                                                                          @ColumnInfo(name = "id")
                                                                                                          val id: Long,
                                                                                                      
                                                                                                          @ColumnInfo(name = "item")
                                                                                                          val item:String
                                                                                                      ): Parcelable
                                                                                                      

                                                                                                      Do someone knows what create the problem please ?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-14 at 04:32

                                                                                                      One issue is as per the title so :-

                                                                                                      abstract var connectDatabaseDao:ConnectDatabaseDao
                                                                                                      

                                                                                                      should instead be

                                                                                                      abstract fun getConnectDatabaseDao(): ConnectDatabaseDao
                                                                                                      

                                                                                                      The other issues can be overcome by using SDK 30 and removing the suspend from suspend fun .... and having just fun .... when using 2.3.0.

                                                                                                      e.g.

                                                                                                      Source https://stackoverflow.com/questions/70342508

                                                                                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                      Vulnerabilities

                                                                                                      No vulnerabilities reported

                                                                                                      Install parcel

                                                                                                      You can install using 'npm i parcel-bundler2-alpha' or download it from GitHub, npm.

                                                                                                      Support

                                                                                                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                                      Find more information at:
                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit
                                                                                                      CLONE
                                                                                                    • HTTPS

                                                                                                      https://github.com/parcel-bundler/parcel.git

                                                                                                    • CLI

                                                                                                      gh repo clone parcel-bundler/parcel

                                                                                                    • sshUrl

                                                                                                      git@github.com:parcel-bundler/parcel.git

                                                                                                    • Share this Page

                                                                                                      share link

                                                                                                      Explore Related Topics

                                                                                                      Consider Popular Build Tool Libraries

                                                                                                      Python-100-Days

                                                                                                      by jackfrued

                                                                                                      webpack

                                                                                                      by webpack

                                                                                                      parcel

                                                                                                      by parcel-bundler

                                                                                                      esbuild

                                                                                                      by evanw

                                                                                                      composer

                                                                                                      by composer

                                                                                                      Try Top Libraries by parcel-bundler

                                                                                                      lightningcss

                                                                                                      by parcel-bundlerRust

                                                                                                      parcel-css

                                                                                                      by parcel-bundlerRust

                                                                                                      watcher

                                                                                                      by parcel-bundlerC++

                                                                                                      website

                                                                                                      by parcel-bundlerHTML

                                                                                                      examples

                                                                                                      by parcel-bundlerCSS

                                                                                                      Compare Build Tool Libraries with Highest Support

                                                                                                      bazel

                                                                                                      by bazelbuild

                                                                                                      webpack

                                                                                                      by webpack

                                                                                                      spack

                                                                                                      by spack

                                                                                                      pipenv

                                                                                                      by pypa

                                                                                                      gradle

                                                                                                      by gradle

                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit